├── .gitattributes ├── .gitignore ├── LICENSE ├── ReadMe.md ├── Resources ├── FitAll.png ├── Home.png ├── Pan.png ├── Rotate.png ├── Zoom.png ├── box.png ├── chamfer.png ├── common.png ├── cone.png ├── cut.png ├── cylinder.png ├── extrude.png ├── fillet.png ├── fuse.png ├── helix.png ├── lamp.png ├── loft.png ├── revolve.png ├── sphere.png ├── torus.png └── wedge.png ├── main.cpp ├── occQt.cpp ├── occQt.h ├── occQt.pro ├── occQt.ui ├── occView.cpp ├── occView.h ├── occqt.qrc └── occt.natvis /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Fortran module files 13 | *.mod 14 | 15 | # Compiled Static libraries 16 | *.lai 17 | *.la 18 | *.a 19 | *.lib 20 | 21 | # Executables 22 | *.exe 23 | *.out 24 | *.app 25 | 26 | # ========================= 27 | # Operating System Files 28 | # ========================= 29 | 30 | # OSX 31 | # ========================= 32 | 33 | .DS_Store 34 | .AppleDouble 35 | .LSOverride 36 | 37 | # Icon must end with two \r 38 | Icon 39 | 40 | # Thumbnails 41 | ._* 42 | 43 | # Files that might appear on external disk 44 | .Spotlight-V100 45 | .Trashes 46 | 47 | # Directories potentially created on remote AFP share 48 | .AppleDB 49 | .AppleDesktop 50 | Network Trash Folder 51 | Temporary Items 52 | .apdisk 53 | 54 | # Windows 55 | # ========================= 56 | 57 | # Windows image file caches 58 | Thumbs.db 59 | ehthumbs.db 60 | 61 | # Folder config file 62 | Desktop.ini 63 | 64 | # Recycle Bin used on file shares 65 | $RECYCLE.BIN/ 66 | 67 | # Windows Installer files 68 | *.cab 69 | *.msi 70 | *.msm 71 | *.msp 72 | 73 | #Visual Studio files 74 | *.[Oo]bj 75 | *.user 76 | *.aps 77 | *.pch 78 | *.vspscc 79 | *.vssscc 80 | *_i.c 81 | *_p.c 82 | *.ncb 83 | *.suo 84 | *.tlb 85 | *.tlh 86 | *.bak 87 | *.[Cc]ache 88 | *.ilk 89 | *.log 90 | *.lib 91 | *.sbr 92 | *.sdf 93 | *.opensdf 94 | *.unsuccessfulbuild 95 | ipch/ 96 | obj/ 97 | [Bb]in 98 | [Dd]ebug*/ 99 | [Rr]elease*/ 100 | Ankh.NoLoad 101 | 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Shing Liu (eryar@163.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | =========== 3 | 4 | Copyright (c) 2018 Shing Liu (eryar@163.com) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | Building occQt on Linux 25 | ======================= 26 | First you need the qt and Mesa/OpenGL development files: 27 | sudo apt-get install qt5-default qt5-qmake qtbase5-dev-tools qtcreator libglu1-mesa-dev mesa-common-dev 28 | 29 | For Open CASCADE Official Edition 30 | --------------------------------- 31 | 1. Build Open CASCADE from source with CMake(https://dev.opencascade.org/doc/overview/html/occt_dev_guides__building_cmake.html); 32 | 2. Build occQt with Qt Creator; 33 | 34 | 35 | For Open CASCADE Community Edition 36 | ---------------------------------- 37 | Then from the FreeCad ppa (make sure you have http://ppa.launchpad.net/freecad-maintainers/freecad-daily/ubuntu in your apt sources list): 38 | sudo apt-get install oce-draw liboce-modeling-dev liboce-ocaf-dev 39 | 40 | Building occQt on Windows 41 | ========================= 42 | 43 | For QtCreator 44 | ------------------------------- 45 | Open the occQt.pro from the Qt menu and set 46 | the variable CASROOT Opencascade installation path 47 | 48 | For VisualStudio 49 | ------------------------------- 50 | First you need the qt-vs-addin, you can download it from here: http://download.qt.io/archive/vsaddin/ 51 | open th occQt.pro and set the variable CASROOT Opencascade installation path 52 | then open the occQt.pro from the Qt menu in the Visual Studio. 53 | 54 | 中国用户 55 | -------- 56 | 对于中国用户,推荐清华大学开源软件镜像站去下载开源程序相关资源,速度快: 57 | https://mirrors.tuna.tsinghua.edu.cn/ 58 | 59 | 关于Qt的资源镜像地址为: 60 | https://mirrors.tuna.tsinghua.edu.cn/qt/ 61 | 62 | Note 63 | ==== 64 | 1. Demonstrate the operations for the OpenCASCADE viewer, such as pan, zoom and rotate; 65 | the view manipulate mainly by the middle button of the mouse, and left button is used 66 | to pick and select; 67 | 2. Demonstrate the primitive shape construction algorithms usage, such as box, cone, 68 | sphere, cylinder and torus creation; 69 | 3. Demonstrate some modeling algorithms, such as prism, revol, loft and fillet, chamfer; 70 | 4. Demonstrate boolean operations, such as cut, fuse and common; 71 | 5. Demonstrate the helix algorithms; 72 | 6. Enjoy! 73 | 74 | Contributors 75 | ============ 76 | Alessandro Screm 77 | https://github.com/AlessandroScrem/occQt 78 | 79 | Sönke J. Peters 80 | https://github.com/speters 81 | 82 | Anton Fosselius 83 | https://github.com/maidenone 84 | 85 | Keith Preston 86 | https://github.com/shrdluk 87 | 88 | Paul Hentschel 89 | https://github.com/hpmachining 90 | 91 | 92 | Feedback 93 | -------- 94 | For more info, please visit the web site: 95 | http://www.cppblog.com/eryar/ 96 | 97 | Shing Liu: eryar@163.com 98 | -------------------------------------------------------------------------------- /Resources/FitAll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/FitAll.png -------------------------------------------------------------------------------- /Resources/Home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/Home.png -------------------------------------------------------------------------------- /Resources/Pan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/Pan.png -------------------------------------------------------------------------------- /Resources/Rotate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/Rotate.png -------------------------------------------------------------------------------- /Resources/Zoom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/Zoom.png -------------------------------------------------------------------------------- /Resources/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/box.png -------------------------------------------------------------------------------- /Resources/chamfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/chamfer.png -------------------------------------------------------------------------------- /Resources/common.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/common.png -------------------------------------------------------------------------------- /Resources/cone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/cone.png -------------------------------------------------------------------------------- /Resources/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/cut.png -------------------------------------------------------------------------------- /Resources/cylinder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/cylinder.png -------------------------------------------------------------------------------- /Resources/extrude.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/extrude.png -------------------------------------------------------------------------------- /Resources/fillet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/fillet.png -------------------------------------------------------------------------------- /Resources/fuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/fuse.png -------------------------------------------------------------------------------- /Resources/helix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/helix.png -------------------------------------------------------------------------------- /Resources/lamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/lamp.png -------------------------------------------------------------------------------- /Resources/loft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/loft.png -------------------------------------------------------------------------------- /Resources/revolve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/revolve.png -------------------------------------------------------------------------------- /Resources/sphere.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/sphere.png -------------------------------------------------------------------------------- /Resources/torus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/torus.png -------------------------------------------------------------------------------- /Resources/wedge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eryar/occQt/7446f06d6f1ed1932b1dae36bfc78bed9b645102/Resources/wedge.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Shing Liu All Rights Reserved. 3 | * 4 | * File : main.cpp 5 | * Author : Shing Liu(eryar@163.com) 6 | * Date : 2018-01-08 20:00 7 | * Version : OpenCASCADE7.2.0 & Qt5.7.1 8 | * 9 | * Description : OpenCASCADE with Qt demo. 10 | */ 11 | 12 | 13 | #include "occQt.h" 14 | #include 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | QApplication a(argc, argv); 19 | 20 | occQt w; 21 | w.show(); 22 | 23 | return a.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /occQt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Shing Liu All Rights Reserved. 3 | * 4 | * File : occQt.cpp 5 | * Author : Shing Liu(eryar@163.com) 6 | * Date : 2018-01-08 21:00 7 | * Version : OpenCASCADE7.2.0 & Qt5.7.1 8 | * 9 | * Description : Qt main window for OpenCASCADE. 10 | */ 11 | 12 | #include "occQt.h" 13 | #include "occView.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #include 55 | #include 56 | 57 | #include 58 | #include 59 | 60 | #include 61 | #include 62 | #include 63 | 64 | #include 65 | 66 | occQt::occQt(QWidget *parent) 67 | : QMainWindow(parent) 68 | { 69 | ui.setupUi(this); 70 | 71 | myOccView = new OccView(this); 72 | 73 | setCentralWidget(myOccView); 74 | 75 | createActions(); 76 | createMenus(); 77 | createToolBars(); 78 | } 79 | 80 | occQt::~occQt() 81 | { 82 | 83 | } 84 | 85 | void occQt::createActions( void ) 86 | { 87 | // File 88 | connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close())); 89 | 90 | // View 91 | connect(ui.actionZoom, SIGNAL(triggered()), myOccView, SLOT(zoom())); 92 | connect(ui.actionPan, SIGNAL(triggered()), myOccView, SLOT(pan())); 93 | connect(ui.actionRotate, SIGNAL(triggered()), myOccView, SLOT(rotate())); 94 | 95 | connect(ui.actionReset, SIGNAL(triggered()), myOccView, SLOT(reset())); 96 | connect(ui.actionFitAll, SIGNAL(triggered()), myOccView, SLOT(fitAll())); 97 | 98 | // Primitive 99 | connect(ui.actionBox, SIGNAL(triggered()), this, SLOT(makeBox())); 100 | connect(ui.actionCone, SIGNAL(triggered()), this, SLOT(makeCone())); 101 | connect(ui.actionSphere, SIGNAL(triggered()), this, SLOT(makeSphere())); 102 | connect(ui.actionCylinder, SIGNAL(triggered()), this, SLOT(makeCylinder())); 103 | connect(ui.actionTorus, SIGNAL(triggered()), this, SLOT(makeTorus())); 104 | 105 | // Modeling 106 | connect(ui.actionFillet, SIGNAL(triggered()), this, SLOT(makeFillet())); 107 | connect(ui.actionChamfer, SIGNAL(triggered()), this, SLOT(makeChamfer())); 108 | connect(ui.actionExtrude, SIGNAL(triggered()), this, SLOT(makeExtrude())); 109 | connect(ui.actionRevolve, SIGNAL(triggered()), this, SLOT(makeRevol())); 110 | connect(ui.actionLoft, SIGNAL(triggered()), this, SLOT(makeLoft())); 111 | 112 | connect(ui.actionCut, SIGNAL(triggered()), this, SLOT(testCut())); 113 | connect(ui.actionFuse, SIGNAL(triggered()), this, SLOT(testFuse())); 114 | connect(ui.actionCommon, SIGNAL(triggered()), this, SLOT(testCommon())); 115 | 116 | connect(ui.actionHelix, SIGNAL(triggered()), this, SLOT(testHelix())); 117 | 118 | // Help 119 | connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(about())); 120 | } 121 | 122 | void occQt::createMenus( void ) 123 | { 124 | } 125 | 126 | void occQt::createToolBars( void ) 127 | { 128 | QToolBar* aToolBar = addToolBar(tr("&Navigate")); 129 | aToolBar->addAction(ui.actionZoom); 130 | aToolBar->addAction(ui.actionPan); 131 | aToolBar->addAction(ui.actionRotate); 132 | 133 | aToolBar = addToolBar(tr("&View")); 134 | aToolBar->addAction(ui.actionReset); 135 | aToolBar->addAction(ui.actionFitAll); 136 | 137 | aToolBar = addToolBar(tr("&Primitive")); 138 | aToolBar->addAction(ui.actionBox); 139 | aToolBar->addAction(ui.actionCone); 140 | aToolBar->addAction(ui.actionSphere); 141 | aToolBar->addAction(ui.actionCylinder); 142 | aToolBar->addAction(ui.actionTorus); 143 | 144 | aToolBar = addToolBar(tr("&Modeling")); 145 | aToolBar->addAction(ui.actionFillet); 146 | aToolBar->addAction(ui.actionChamfer); 147 | aToolBar->addAction(ui.actionExtrude); 148 | aToolBar->addAction(ui.actionRevolve); 149 | aToolBar->addAction(ui.actionLoft); 150 | aToolBar->addSeparator(); 151 | aToolBar->addAction(ui.actionCut); 152 | aToolBar->addAction(ui.actionFuse); 153 | aToolBar->addAction(ui.actionCommon); 154 | aToolBar->addSeparator(); 155 | aToolBar->addAction(ui.actionHelix); 156 | 157 | aToolBar = addToolBar(tr("Help")); 158 | aToolBar->addAction(ui.actionAbout); 159 | } 160 | 161 | void occQt::about() 162 | { 163 | QMessageBox::about(this, tr("About occQt"), 164 | tr("

occQt 2.0

" 165 | "

Copyright © 2014 eryar@163.com" 166 | "

occQt is a demo applicaton about Qt and OpenCASCADE.")); 167 | } 168 | 169 | void occQt::makeBox() 170 | { 171 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(3.0, 4.0, 5.0).Shape(); 172 | Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox); 173 | 174 | anAisBox->SetColor(Quantity_NOC_AZURE); 175 | 176 | myOccView->getContext()->Display(anAisBox, Standard_True); 177 | } 178 | 179 | void occQt::makeCone() 180 | { 181 | gp_Ax2 anAxis; 182 | anAxis.SetLocation(gp_Pnt(0.0, 10.0, 0.0)); 183 | 184 | TopoDS_Shape aTopoReducer = BRepPrimAPI_MakeCone(anAxis, 3.0, 1.5, 5.0).Shape(); 185 | Handle(AIS_Shape) anAisReducer = new AIS_Shape(aTopoReducer); 186 | 187 | anAisReducer->SetColor(Quantity_NOC_BISQUE); 188 | 189 | anAxis.SetLocation(gp_Pnt(8.0, 10.0, 0.0)); 190 | TopoDS_Shape aTopoCone = BRepPrimAPI_MakeCone(anAxis, 3.0, 0.0, 5.0).Shape(); 191 | Handle(AIS_Shape) anAisCone = new AIS_Shape(aTopoCone); 192 | 193 | anAisCone->SetColor(Quantity_NOC_CHOCOLATE); 194 | 195 | myOccView->getContext()->Display(anAisReducer, Standard_True); 196 | myOccView->getContext()->Display(anAisCone, Standard_True); 197 | } 198 | 199 | void occQt::makeSphere() 200 | { 201 | gp_Ax2 anAxis; 202 | anAxis.SetLocation(gp_Pnt(0.0, 20.0, 0.0)); 203 | 204 | TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 3.0).Shape(); 205 | Handle(AIS_Shape) anAisSphere = new AIS_Shape(aTopoSphere); 206 | 207 | anAisSphere->SetColor(Quantity_NOC_BLUE1); 208 | 209 | myOccView->getContext()->Display(anAisSphere, Standard_True); 210 | } 211 | 212 | void occQt::makeCylinder() 213 | { 214 | gp_Ax2 anAxis; 215 | anAxis.SetLocation(gp_Pnt(0.0, 30.0, 0.0)); 216 | 217 | TopoDS_Shape aTopoCylinder = BRepPrimAPI_MakeCylinder(anAxis, 3.0, 5.0).Shape(); 218 | Handle(AIS_Shape) anAisCylinder = new AIS_Shape(aTopoCylinder); 219 | 220 | anAisCylinder->SetColor(Quantity_NOC_RED); 221 | 222 | anAxis.SetLocation(gp_Pnt(8.0, 30.0, 0.0)); 223 | TopoDS_Shape aTopoPie = BRepPrimAPI_MakeCylinder(anAxis, 3.0, 5.0, M_PI_2 * 3.0).Shape(); 224 | Handle(AIS_Shape) anAisPie = new AIS_Shape(aTopoPie); 225 | 226 | anAisPie->SetColor(Quantity_NOC_TAN); 227 | 228 | myOccView->getContext()->Display(anAisCylinder, Standard_True); 229 | myOccView->getContext()->Display(anAisPie, Standard_True); 230 | } 231 | 232 | void occQt::makeTorus() 233 | { 234 | gp_Ax2 anAxis; 235 | anAxis.SetLocation(gp_Pnt(0.0, 40.0, 0.0)); 236 | 237 | TopoDS_Shape aTopoTorus = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0).Shape(); 238 | Handle(AIS_Shape) anAisTorus = new AIS_Shape(aTopoTorus); 239 | 240 | anAisTorus->SetColor(Quantity_NOC_YELLOW); 241 | 242 | anAxis.SetLocation(gp_Pnt(8.0, 40.0, 0.0)); 243 | TopoDS_Shape aTopoElbow = BRepPrimAPI_MakeTorus(anAxis, 3.0, 1.0, M_PI_2).Shape(); 244 | Handle(AIS_Shape) anAisElbow = new AIS_Shape(aTopoElbow); 245 | 246 | anAisElbow->SetColor(Quantity_NOC_THISTLE); 247 | 248 | myOccView->getContext()->Display(anAisTorus, Standard_True); 249 | myOccView->getContext()->Display(anAisElbow, Standard_True); 250 | } 251 | 252 | void occQt::makeFillet() 253 | { 254 | gp_Ax2 anAxis; 255 | anAxis.SetLocation(gp_Pnt(0.0, 50.0, 0.0)); 256 | 257 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0).Shape(); 258 | BRepFilletAPI_MakeFillet MF(aTopoBox); 259 | 260 | // Add all the edges to fillet. 261 | for (TopExp_Explorer ex(aTopoBox, TopAbs_EDGE); ex.More(); ex.Next()) 262 | { 263 | MF.Add(1.0, TopoDS::Edge(ex.Current())); 264 | } 265 | 266 | Handle(AIS_Shape) anAisShape = new AIS_Shape(MF.Shape()); 267 | anAisShape->SetColor(Quantity_NOC_VIOLET); 268 | 269 | myOccView->getContext()->Display(anAisShape, Standard_True); 270 | } 271 | 272 | void occQt::makeChamfer() 273 | { 274 | gp_Ax2 anAxis; 275 | anAxis.SetLocation(gp_Pnt(8.0, 50.0, 0.0)); 276 | 277 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0).Shape(); 278 | BRepFilletAPI_MakeChamfer MC(aTopoBox); 279 | TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap; 280 | 281 | TopExp::MapShapesAndAncestors(aTopoBox, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap); 282 | 283 | for (Standard_Integer i = 1; i <= aEdgeFaceMap.Extent(); ++i) 284 | { 285 | TopoDS_Edge anEdge = TopoDS::Edge(aEdgeFaceMap.FindKey(i)); 286 | TopoDS_Face aFace = TopoDS::Face(aEdgeFaceMap.FindFromIndex(i).First()); 287 | 288 | MC.Add(0.6, 0.6, anEdge, aFace); 289 | } 290 | 291 | Handle(AIS_Shape) anAisShape = new AIS_Shape(MC.Shape()); 292 | anAisShape->SetColor(Quantity_NOC_TOMATO); 293 | 294 | myOccView->getContext()->Display(anAisShape, Standard_True); 295 | } 296 | 297 | void occQt::makeExtrude() 298 | { 299 | // prism a vertex result is an edge. 300 | TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0)); 301 | TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0)); 302 | Handle(AIS_Shape) anAisPrismVertex = new AIS_Shape(aPrismVertex); 303 | 304 | // prism an edge result is a face. 305 | TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0)); 306 | TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0)); 307 | Handle(AIS_Shape) anAisPrismEdge = new AIS_Shape(aPrismEdge); 308 | 309 | // prism a wire result is a shell. 310 | gp_Ax2 anAxis; 311 | anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0)); 312 | 313 | TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0)); 314 | TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); 315 | TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0)); 316 | Handle(AIS_Shape) anAisPrismCircle = new AIS_Shape(aPrismCircle); 317 | 318 | // prism a face or a shell result is a solid. 319 | anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0)); 320 | TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0)); 321 | TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge); 322 | TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire); 323 | TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0)); 324 | Handle(AIS_Shape) anAisPrismEllipse = new AIS_Shape(aPrismEllipse); 325 | 326 | anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP); 327 | anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF); 328 | anAisPrismCircle->SetColor(Quantity_NOC_PERU); 329 | anAisPrismEllipse->SetColor(Quantity_NOC_PINK); 330 | 331 | myOccView->getContext()->Display(anAisPrismVertex, Standard_True); 332 | myOccView->getContext()->Display(anAisPrismEdge, Standard_True); 333 | myOccView->getContext()->Display(anAisPrismCircle, Standard_True); 334 | myOccView->getContext()->Display(anAisPrismEllipse, Standard_True); 335 | } 336 | 337 | void occQt::makeRevol() 338 | { 339 | gp_Ax1 anAxis; 340 | 341 | // revol a vertex result is an edge. 342 | anAxis.SetLocation(gp_Pnt(0.0, 70.0, 0.0)); 343 | TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(2.0, 70.0, 0.0)); 344 | TopoDS_Shape aRevolVertex = BRepPrimAPI_MakeRevol(aVertex, anAxis); 345 | Handle(AIS_Shape) anAisRevolVertex = new AIS_Shape(aRevolVertex); 346 | 347 | // revol an edge result is a face. 348 | anAxis.SetLocation(gp_Pnt(8.0, 70.0, 0.0)); 349 | TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(6.0, 70.0, 0.0), gp_Pnt(6.0, 70.0, 5.0)); 350 | TopoDS_Shape aRevolEdge = BRepPrimAPI_MakeRevol(anEdge, anAxis); 351 | Handle(AIS_Shape) anAisRevolEdge = new AIS_Shape(aRevolEdge); 352 | 353 | // revol a wire result is a shell. 354 | anAxis.SetLocation(gp_Pnt(20.0, 70.0, 0.0)); 355 | anAxis.SetDirection(gp::DY()); 356 | 357 | TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(15.0, 70.0, 0.0), gp::DZ()), 1.5)); 358 | TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); 359 | TopoDS_Shape aRevolCircle = BRepPrimAPI_MakeRevol(aCircleWire, anAxis, M_PI_2); 360 | Handle(AIS_Shape) anAisRevolCircle = new AIS_Shape(aRevolCircle); 361 | 362 | // revol a face result is a solid. 363 | anAxis.SetLocation(gp_Pnt(30.0, 70.0, 0.0)); 364 | anAxis.SetDirection(gp::DY()); 365 | 366 | TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(gp_Ax2(gp_Pnt(25.0, 70.0, 0.0), gp::DZ()), 3.0, 2.0)); 367 | TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge); 368 | TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire); 369 | TopoDS_Shape aRevolEllipse = BRepPrimAPI_MakeRevol(aEllipseFace, anAxis, M_PI_4); 370 | Handle(AIS_Shape) anAisRevolEllipse = new AIS_Shape(aRevolEllipse); 371 | 372 | anAisRevolVertex->SetColor(Quantity_NOC_LIMEGREEN); 373 | anAisRevolEdge->SetColor(Quantity_NOC_LINEN); 374 | anAisRevolCircle->SetColor(Quantity_NOC_MAGENTA1); 375 | anAisRevolEllipse->SetColor(Quantity_NOC_MAROON); 376 | 377 | myOccView->getContext()->Display(anAisRevolVertex, Standard_True); 378 | myOccView->getContext()->Display(anAisRevolEdge, Standard_True); 379 | myOccView->getContext()->Display(anAisRevolCircle, Standard_True); 380 | myOccView->getContext()->Display(anAisRevolEllipse, Standard_True); 381 | } 382 | 383 | void occQt::makeLoft() 384 | { 385 | // bottom wire. 386 | TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(gp_Ax2(gp_Pnt(0.0, 80.0, 0.0), gp::DZ()), 1.5)); 387 | TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); 388 | 389 | // top wire. 390 | BRepBuilderAPI_MakePolygon aPolygon; 391 | aPolygon.Add(gp_Pnt(-3.0, 77.0, 6.0)); 392 | aPolygon.Add(gp_Pnt(3.0, 77.0, 6.0)); 393 | aPolygon.Add(gp_Pnt(3.0, 83.0, 6.0)); 394 | aPolygon.Add(gp_Pnt(-3.0, 83.0, 6.0)); 395 | aPolygon.Close(); 396 | 397 | BRepOffsetAPI_ThruSections aShellGenerator; 398 | BRepOffsetAPI_ThruSections aSolidGenerator(true); 399 | 400 | aShellGenerator.AddWire(aCircleWire); 401 | aShellGenerator.AddWire(aPolygon.Wire()); 402 | 403 | aSolidGenerator.AddWire(aCircleWire); 404 | aSolidGenerator.AddWire(aPolygon.Wire()); 405 | 406 | // translate the solid. 407 | gp_Trsf aTrsf; 408 | aTrsf.SetTranslation(gp_Vec(18.0, 0.0, 0.0)); 409 | BRepBuilderAPI_Transform aTransform(aSolidGenerator.Shape(), aTrsf); 410 | 411 | Handle(AIS_Shape) anAisShell = new AIS_Shape(aShellGenerator.Shape()); 412 | Handle(AIS_Shape) anAisSolid = new AIS_Shape(aTransform.Shape()); 413 | 414 | anAisShell->SetColor(Quantity_NOC_OLIVEDRAB); 415 | anAisSolid->SetColor(Quantity_NOC_PEACHPUFF); 416 | 417 | myOccView->getContext()->Display(anAisShell, Standard_True); 418 | myOccView->getContext()->Display(anAisSolid, Standard_True); 419 | } 420 | 421 | void occQt::testCut() 422 | { 423 | gp_Ax2 anAxis; 424 | anAxis.SetLocation(gp_Pnt(0.0, 90.0, 0.0)); 425 | 426 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0).Shape(); 427 | TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5).Shape(); 428 | TopoDS_Shape aCuttedShape1 = BRepAlgoAPI_Cut(aTopoBox, aTopoSphere); 429 | TopoDS_Shape aCuttedShape2 = BRepAlgoAPI_Cut(aTopoSphere, aTopoBox); 430 | 431 | gp_Trsf aTrsf; 432 | aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); 433 | BRepBuilderAPI_Transform aTransform1(aCuttedShape1, aTrsf); 434 | 435 | aTrsf.SetTranslation(gp_Vec(16.0, 0.0, 0.0)); 436 | BRepBuilderAPI_Transform aTransform2(aCuttedShape2, aTrsf); 437 | 438 | Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox); 439 | Handle(AIS_Shape) anAisSphere = new AIS_Shape(aTopoSphere); 440 | Handle(AIS_Shape) anAisCuttedShape1 = new AIS_Shape(aTransform1.Shape()); 441 | Handle(AIS_Shape) anAisCuttedShape2 = new AIS_Shape(aTransform2.Shape()); 442 | 443 | anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); 444 | anAisSphere->SetColor(Quantity_NOC_STEELBLUE); 445 | anAisCuttedShape1->SetColor(Quantity_NOC_TAN); 446 | anAisCuttedShape2->SetColor(Quantity_NOC_SALMON); 447 | 448 | myOccView->getContext()->Display(anAisBox, Standard_True); 449 | myOccView->getContext()->Display(anAisSphere, Standard_True); 450 | myOccView->getContext()->Display(anAisCuttedShape1, Standard_True); 451 | myOccView->getContext()->Display(anAisCuttedShape2, Standard_True); 452 | } 453 | 454 | void occQt::testFuse() 455 | { 456 | gp_Ax2 anAxis; 457 | anAxis.SetLocation(gp_Pnt(0.0, 100.0, 0.0)); 458 | 459 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0).Shape(); 460 | TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5).Shape(); 461 | TopoDS_Shape aFusedShape = BRepAlgoAPI_Fuse(aTopoBox, aTopoSphere); 462 | 463 | gp_Trsf aTrsf; 464 | aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); 465 | BRepBuilderAPI_Transform aTransform(aFusedShape, aTrsf); 466 | 467 | Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox); 468 | Handle(AIS_Shape) anAisSphere = new AIS_Shape(aTopoSphere); 469 | Handle(AIS_Shape) anAisFusedShape = new AIS_Shape(aTransform.Shape()); 470 | 471 | anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); 472 | anAisSphere->SetColor(Quantity_NOC_STEELBLUE); 473 | anAisFusedShape->SetColor(Quantity_NOC_ROSYBROWN); 474 | 475 | myOccView->getContext()->Display(anAisBox, Standard_True); 476 | myOccView->getContext()->Display(anAisSphere, Standard_True); 477 | myOccView->getContext()->Display(anAisFusedShape, Standard_True); 478 | } 479 | 480 | void occQt::testCommon() 481 | { 482 | gp_Ax2 anAxis; 483 | anAxis.SetLocation(gp_Pnt(0.0, 110.0, 0.0)); 484 | 485 | TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0).Shape(); 486 | TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5).Shape(); 487 | TopoDS_Shape aCommonShape = BRepAlgoAPI_Common(aTopoBox, aTopoSphere); 488 | 489 | gp_Trsf aTrsf; 490 | aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); 491 | BRepBuilderAPI_Transform aTransform(aCommonShape, aTrsf); 492 | 493 | Handle(AIS_Shape) anAisBox = new AIS_Shape(aTopoBox); 494 | Handle(AIS_Shape) anAisSphere = new AIS_Shape(aTopoSphere); 495 | Handle(AIS_Shape) anAisCommonShape = new AIS_Shape(aTransform.Shape()); 496 | 497 | anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); 498 | anAisSphere->SetColor(Quantity_NOC_STEELBLUE); 499 | anAisCommonShape->SetColor(Quantity_NOC_ROYALBLUE); 500 | 501 | myOccView->getContext()->Display(anAisBox, Standard_True); 502 | myOccView->getContext()->Display(anAisSphere, Standard_True); 503 | myOccView->getContext()->Display(anAisCommonShape, Standard_True); 504 | } 505 | 506 | void occQt::testHelix() 507 | { 508 | makeCylindricalHelix(); 509 | 510 | makeConicalHelix(); 511 | 512 | makeToroidalHelix(); 513 | } 514 | 515 | void occQt::makeCylindricalHelix() 516 | { 517 | Standard_Real aRadius = 3.0; 518 | Standard_Real aPitch = 1.0; 519 | 520 | // the pcurve is a 2d line in the parametric space. 521 | gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aRadius, aPitch)); 522 | 523 | Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value(); 524 | 525 | Handle(Geom_CylindricalSurface) aCylinder = new Geom_CylindricalSurface(gp::XOY(), aRadius); 526 | 527 | TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 6.0 * M_PI).Edge(); 528 | 529 | gp_Trsf aTrsf; 530 | aTrsf.SetTranslation(gp_Vec(0.0, 120.0, 0.0)); 531 | BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf); 532 | 533 | Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape()); 534 | 535 | myOccView->getContext()->Display(anAisHelixCurve, Standard_True); 536 | 537 | // sweep a circle profile along the helix curve. 538 | // there is no curve3d in the pcurve edge, so approx one. 539 | BRepLib::BuildCurve3d(aHelixEdge); 540 | 541 | gp_Ax2 anAxis; 542 | anAxis.SetDirection(gp_Dir(0.0, 4.0, 1.0)); 543 | anAxis.SetLocation(gp_Pnt(aRadius, 0.0, 0.0)); 544 | 545 | gp_Circ aProfileCircle(anAxis, 0.3); 546 | 547 | TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge(); 548 | TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire(); 549 | TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face(); 550 | 551 | TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire(); 552 | 553 | BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace); 554 | 555 | if (aPipeMaker.IsDone()) 556 | { 557 | aTrsf.SetTranslation(gp_Vec(8.0, 120.0, 0.0)); 558 | BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf); 559 | 560 | Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape()); 561 | anAisPipe->SetColor(Quantity_NOC_CORAL); 562 | myOccView->getContext()->Display(anAisPipe, Standard_True); 563 | } 564 | } 565 | 566 | /** 567 | * make conical helix, it is the same as the cylindrical helix, 568 | * the only different is the surface. 569 | */ 570 | void occQt::makeConicalHelix() 571 | { 572 | Standard_Real aRadius = 3.0; 573 | Standard_Real aPitch = 1.0; 574 | 575 | // the pcurve is a 2d line in the parametric space. 576 | gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aRadius, aPitch)); 577 | 578 | Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value(); 579 | 580 | Handle(Geom_ConicalSurface) aCylinder = new Geom_ConicalSurface(gp::XOY(), M_PI / 6.0, aRadius); 581 | 582 | TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 6.0 * M_PI).Edge(); 583 | 584 | gp_Trsf aTrsf; 585 | aTrsf.SetTranslation(gp_Vec(18.0, 120.0, 0.0)); 586 | BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf); 587 | 588 | Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape()); 589 | 590 | myOccView->getContext()->Display(anAisHelixCurve, Standard_True); 591 | 592 | // sweep a circle profile along the helix curve. 593 | // there is no curve3d in the pcurve edge, so approx one. 594 | BRepLib::BuildCurve3d(aHelixEdge); 595 | 596 | gp_Ax2 anAxis; 597 | anAxis.SetDirection(gp_Dir(0.0, 4.0, 1.0)); 598 | anAxis.SetLocation(gp_Pnt(aRadius, 0.0, 0.0)); 599 | 600 | gp_Circ aProfileCircle(anAxis, 0.3); 601 | 602 | TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge(); 603 | TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire(); 604 | TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face(); 605 | 606 | TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire(); 607 | 608 | BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace); 609 | 610 | if (aPipeMaker.IsDone()) 611 | { 612 | aTrsf.SetTranslation(gp_Vec(28.0, 120.0, 0.0)); 613 | BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf); 614 | 615 | Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape()); 616 | anAisPipe->SetColor(Quantity_NOC_DARKGOLDENROD); 617 | myOccView->getContext()->Display(anAisPipe, Standard_True); 618 | } 619 | } 620 | 621 | void occQt::makeToroidalHelix() 622 | { 623 | Standard_Real aRadius = 1.0; 624 | Standard_Real aSlope = 0.05; 625 | 626 | // the pcurve is a 2d line in the parametric space. 627 | gp_Lin2d aLine2d(gp_Pnt2d(0.0, 0.0), gp_Dir2d(aSlope, 1.0)); 628 | 629 | Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, M_PI * 2.0).Value(); 630 | 631 | Handle(Geom_ToroidalSurface) aCylinder = new Geom_ToroidalSurface(gp::XOY(), aRadius * 5.0, aRadius); 632 | 633 | TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSegment, aCylinder, 0.0, 2.0 * M_PI / aSlope).Edge(); 634 | 635 | gp_Trsf aTrsf; 636 | aTrsf.SetTranslation(gp_Vec(45.0, 120.0, 0.0)); 637 | BRepBuilderAPI_Transform aTransform(aHelixEdge, aTrsf); 638 | 639 | Handle(AIS_Shape) anAisHelixCurve = new AIS_Shape(aTransform.Shape()); 640 | 641 | myOccView->getContext()->Display(anAisHelixCurve, Standard_True); 642 | 643 | // sweep a circle profile along the helix curve. 644 | // there is no curve3d in the pcurve edge, so approx one. 645 | BRepLib::BuildCurve3d(aHelixEdge); 646 | 647 | gp_Ax2 anAxis; 648 | anAxis.SetDirection(gp_Dir(0.0, 0.0, 1.0)); 649 | anAxis.SetLocation(gp_Pnt(aRadius * 6.0, 0.0, 0.0)); 650 | 651 | gp_Circ aProfileCircle(anAxis, 0.3); 652 | 653 | TopoDS_Edge aProfileEdge = BRepBuilderAPI_MakeEdge(aProfileCircle).Edge(); 654 | TopoDS_Wire aProfileWire = BRepBuilderAPI_MakeWire(aProfileEdge).Wire(); 655 | TopoDS_Face aProfileFace = BRepBuilderAPI_MakeFace(aProfileWire).Face(); 656 | 657 | TopoDS_Wire aHelixWire = BRepBuilderAPI_MakeWire(aHelixEdge).Wire(); 658 | 659 | BRepOffsetAPI_MakePipe aPipeMaker(aHelixWire, aProfileFace); 660 | 661 | if (aPipeMaker.IsDone()) 662 | { 663 | aTrsf.SetTranslation(gp_Vec(60.0, 120.0, 0.0)); 664 | BRepBuilderAPI_Transform aPipeTransform(aPipeMaker.Shape(), aTrsf); 665 | 666 | Handle(AIS_Shape) anAisPipe = new AIS_Shape(aPipeTransform.Shape()); 667 | anAisPipe->SetColor(Quantity_NOC_CORNSILK1); 668 | myOccView->getContext()->Display(anAisPipe, Standard_True); 669 | } 670 | } 671 | -------------------------------------------------------------------------------- /occQt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Shing Liu All Rights Reserved. 3 | * 4 | * File : occQt.h 5 | * Author : Shing Liu(eryar@163.com) 6 | * Date : 2018-01-08 20:00 7 | * Version : OpenCASCADE7.2.0 & Qt5.7.1 8 | * 9 | * Description : OpenCASCADE in Qt. 10 | */ 11 | 12 | #ifndef OCCQT_H 13 | #define OCCQT_H 14 | 15 | #include "ui_occQt.h" 16 | 17 | #include 18 | 19 | class OccView; 20 | 21 | //! Qt main window which include OpenCASCADE for its central widget. 22 | class occQt : public QMainWindow 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | //! constructor/destructor. 28 | occQt(QWidget *parent = nullptr); 29 | ~occQt(); 30 | 31 | protected: 32 | //! create all the actions. 33 | void createActions(void); 34 | 35 | //! create all the menus. 36 | void createMenus(void); 37 | 38 | //! create the toolbar. 39 | void createToolBars(void); 40 | 41 | //! make cylindrical helix. 42 | void makeCylindricalHelix(void); 43 | 44 | //! make conical helix. 45 | void makeConicalHelix(void); 46 | 47 | //! make toroidal helix. 48 | void makeToroidalHelix(void); 49 | 50 | private slots: 51 | //! show about box. 52 | void about(void); 53 | 54 | //! make box test. 55 | void makeBox(void); 56 | 57 | //! make cone test. 58 | void makeCone(void); 59 | 60 | //! make sphere test. 61 | void makeSphere(void); 62 | 63 | //! make cylinder test. 64 | void makeCylinder(void); 65 | 66 | //! make torus test. 67 | void makeTorus(void); 68 | 69 | //! fillet test. 70 | void makeFillet(void); 71 | 72 | //! chamfer test. 73 | void makeChamfer(void); 74 | 75 | //! test extrude algorithm. 76 | void makeExtrude(void); 77 | 78 | //! test revol algorithm. 79 | void makeRevol(void); 80 | 81 | //! test loft algorithm. 82 | void makeLoft(void); 83 | 84 | //! test boolean operation cut. 85 | void testCut(void); 86 | 87 | //! test boolean operation fuse. 88 | void testFuse(void); 89 | 90 | //! test boolean operation common. 91 | void testCommon(void); 92 | 93 | //! test helix shapes. 94 | void testHelix(void); 95 | 96 | private: 97 | Ui::occQtClass ui; 98 | 99 | // wrapped the widget for occ. 100 | OccView* myOccView; 101 | }; 102 | 103 | #endif // OCCQT_H 104 | -------------------------------------------------------------------------------- /occQt.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2013-08-18T15:52:09 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = occQt 12 | TEMPLATE = app 13 | 14 | SOURCES += main.cpp \ 15 | occQt.cpp \ 16 | occView.cpp 17 | 18 | CONFIG += c++11 19 | 20 | HEADERS += \ 21 | occQt.h \ 22 | occView.h 23 | 24 | FORMS += \ 25 | occQt.ui 26 | 27 | RESOURCES += \ 28 | occqt.qrc 29 | 30 | CASROOT = D:/OpenCASCADE7.4.0/opencascade-7.4.0 31 | 32 | win32 { 33 | DEFINES += \ 34 | WNT 35 | INCLUDEPATH += \ 36 | $$(CASROOT)/inc 37 | 38 | win32-msvc2010 { 39 | compiler=vc10 40 | } 41 | 42 | win32-msvc2012 { 43 | compiler=vc11 44 | } 45 | 46 | win32-msvc2013 { 47 | compiler=vc12 48 | } 49 | 50 | win32-msvc2015 { 51 | compiler=vc14 52 | } 53 | 54 | # Determine 32 / 64 bit and debug / release build 55 | !contains(QMAKE_TARGET.arch, x86_64) { 56 | CONFIG(debug, debug|release) { 57 | message("Debug 32 build") 58 | LIBS += -L$$(CASROOT)/win32/$$compiler/libd 59 | } 60 | else { 61 | message("Release 32 build") 62 | LIBS += -L$$(CASROOT)/win32/$$compiler/lib 63 | } 64 | } 65 | else { 66 | CONFIG(debug, debug|release) { 67 | message("Debug 64 build") 68 | LIBS += -L$$(CASROOT)/win64/$$compiler/libd 69 | } 70 | else { 71 | message("Release 64 build") 72 | LIBS += -L$$(CASROOT)/win64/$$compiler/lib 73 | } 74 | } 75 | } 76 | 77 | linux-g++ { 78 | INCLUDEPATH += \ 79 | $$(CASROOT)/include/opencascade 80 | 81 | LIBS += \ 82 | -L$$(CASROOT)/lib 83 | } 84 | 85 | LIBS += \ 86 | -lTKernel \ 87 | -lTKMath \ 88 | -lTKG3d \ 89 | -lTKBRep \ 90 | -lTKGeomBase\ 91 | -lTKGeomAlgo\ 92 | -lTKTopAlgo \ 93 | -lTKPrim \ 94 | -lTKBO \ 95 | -lTKBool \ 96 | -lTKOffset \ 97 | -lTKService \ 98 | -lTKV3d \ 99 | -lTKOpenGl \ 100 | -lTKFillet 101 | -------------------------------------------------------------------------------- /occQt.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | occQtClass 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | occQt 15 | 16 | 17 | 18 | :/Resources/lamp.png:/Resources/lamp.png 19 | 20 | 21 | 22 | 23 | 24 | 0 25 | 0 26 | 800 27 | 21 28 | 29 | 30 | 31 | 32 | File 33 | 34 | 35 | 36 | 37 | 38 | View 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | Primitive 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Modeling 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | Help 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | Exit 89 | 90 | 91 | Ctrl+Q 92 | 93 | 94 | 95 | 96 | false 97 | 98 | 99 | 100 | :/Resources/Zoom.png:/Resources/Zoom.png 101 | 102 | 103 | Zoom 104 | 105 | 106 | 107 | 108 | false 109 | 110 | 111 | 112 | :/Resources/Pan.png:/Resources/Pan.png 113 | 114 | 115 | Pan 116 | 117 | 118 | 119 | 120 | false 121 | 122 | 123 | false 124 | 125 | 126 | 127 | :/Resources/Rotate.png:/Resources/Rotate.png 128 | 129 | 130 | Rotate 131 | 132 | 133 | 134 | 135 | 136 | :/Resources/Home.png:/Resources/Home.png 137 | 138 | 139 | Reset 140 | 141 | 142 | 143 | 144 | 145 | :/Resources/FitAll.png:/Resources/FitAll.png 146 | 147 | 148 | FitAll 149 | 150 | 151 | 152 | 153 | 154 | :/Resources/lamp.png:/Resources/lamp.png 155 | 156 | 157 | About 158 | 159 | 160 | 161 | 162 | 163 | :/Resources/box.png:/Resources/box.png 164 | 165 | 166 | Box 167 | 168 | 169 | 170 | 171 | 172 | :/Resources/cone.png:/Resources/cone.png 173 | 174 | 175 | Cone 176 | 177 | 178 | 179 | 180 | 181 | :/Resources/sphere.png:/Resources/sphere.png 182 | 183 | 184 | Sphere 185 | 186 | 187 | 188 | 189 | 190 | :/Resources/cylinder.png:/Resources/cylinder.png 191 | 192 | 193 | Cylinder 194 | 195 | 196 | 197 | 198 | 199 | :/Resources/torus.png:/Resources/torus.png 200 | 201 | 202 | Torus 203 | 204 | 205 | 206 | 207 | 208 | :/Resources/fillet.png:/Resources/fillet.png 209 | 210 | 211 | Fillet 212 | 213 | 214 | 215 | 216 | 217 | :/Resources/chamfer.png:/Resources/chamfer.png 218 | 219 | 220 | Chamfer 221 | 222 | 223 | 224 | 225 | 226 | :/Resources/extrude.png:/Resources/extrude.png 227 | 228 | 229 | Extrude 230 | 231 | 232 | 233 | 234 | 235 | :/Resources/revolve.png:/Resources/revolve.png 236 | 237 | 238 | Rovelve 239 | 240 | 241 | 242 | 243 | 244 | :/Resources/loft.png:/Resources/loft.png 245 | 246 | 247 | Loft 248 | 249 | 250 | 251 | 252 | 253 | :/Resources/cut.png:/Resources/cut.png 254 | 255 | 256 | Cut 257 | 258 | 259 | 260 | 261 | 262 | :/Resources/fuse.png:/Resources/fuse.png 263 | 264 | 265 | Fuse 266 | 267 | 268 | 269 | 270 | 271 | :/Resources/common.png:/Resources/common.png 272 | 273 | 274 | Common 275 | 276 | 277 | 278 | 279 | 280 | :/Resources/helix.png:/Resources/helix.png 281 | 282 | 283 | Helix 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | -------------------------------------------------------------------------------- /occView.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Shing Liu All Rights Reserved. 3 | * 4 | * File : OccView.cpp 5 | * Author : Shing Liu(eryar@163.com) 6 | * Date : 2018-01-08 21:00 7 | * Version : OpenCASCADE7.2.0 & Qt5.7.1 8 | * 9 | * Description : Qt widget for OpenCASCADE viewer. 10 | */ 11 | 12 | #include 13 | 14 | #include "occView.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #ifdef WNT 27 | #include 28 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) 29 | #include 30 | #else 31 | #undef Bool 32 | #undef CursorShape 33 | #undef None 34 | #undef KeyPress 35 | #undef KeyRelease 36 | #undef FocusIn 37 | #undef FocusOut 38 | #undef FontChange 39 | #undef Expose 40 | #include 41 | #endif 42 | 43 | 44 | static Handle(Graphic3d_GraphicDriver)& GetGraphicDriver() 45 | { 46 | static Handle(Graphic3d_GraphicDriver) aGraphicDriver; 47 | return aGraphicDriver; 48 | } 49 | 50 | OccView::OccView(QWidget* parent ) 51 | : QWidget(parent), 52 | myXmin(0), 53 | myYmin(0), 54 | myXmax(0), 55 | myYmax(0), 56 | myCurrentMode(CurAction3d_DynamicRotation), 57 | myDegenerateModeIsOn(Standard_True), 58 | myRectBand(NULL) 59 | { 60 | // No Background 61 | setBackgroundRole( QPalette::NoRole ); 62 | 63 | // set focus policy to threat QContextMenuEvent from keyboard 64 | setFocusPolicy(Qt::StrongFocus); 65 | setAttribute(Qt::WA_PaintOnScreen); 66 | setAttribute(Qt::WA_NoSystemBackground); 67 | 68 | // Enable the mouse tracking, by default the mouse tracking is disabled. 69 | setMouseTracking( true ); 70 | 71 | init(); 72 | } 73 | 74 | void OccView::init() 75 | { 76 | // Create Aspect_DisplayConnection 77 | Handle(Aspect_DisplayConnection) aDisplayConnection = 78 | new Aspect_DisplayConnection(); 79 | 80 | // Get graphic driver if it exists, otherwise initialise it 81 | if (GetGraphicDriver().IsNull()) 82 | { 83 | GetGraphicDriver() = new OpenGl_GraphicDriver(aDisplayConnection); 84 | } 85 | 86 | // Get window handle. This returns something suitable for all platforms. 87 | WId window_handle = (WId) winId(); 88 | 89 | // Create appropriate window for platform 90 | #ifdef WNT 91 | Handle(WNT_Window) wind = new WNT_Window((Aspect_Handle) window_handle); 92 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) 93 | Handle(Cocoa_Window) wind = new Cocoa_Window((NSView *) window_handle); 94 | #else 95 | Handle(Xw_Window) wind = new Xw_Window(aDisplayConnection, (Window) window_handle); 96 | #endif 97 | 98 | // Create V3dViewer and V3d_View 99 | myViewer = new V3d_Viewer(GetGraphicDriver(), Standard_ExtString("viewer3d")); 100 | 101 | myView = myViewer->CreateView(); 102 | 103 | myView->SetWindow(wind); 104 | if (!wind->IsMapped()) wind->Map(); 105 | 106 | // Create AISInteractiveContext 107 | myContext = new AIS_InteractiveContext(myViewer); 108 | 109 | // Set up lights etc 110 | myViewer->SetDefaultLights(); 111 | myViewer->SetLightOn(); 112 | 113 | myView->SetBackgroundColor(Quantity_NOC_BLACK); 114 | myView->MustBeResized(); 115 | myView->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_GOLD, 0.08, V3d_ZBUFFER); 116 | 117 | myContext->SetDisplayMode(AIS_Shaded, Standard_True); 118 | } 119 | 120 | const Handle(AIS_InteractiveContext)& OccView::getContext() const 121 | { 122 | return myContext; 123 | } 124 | 125 | /*! 126 | Get paint engine for the OpenGL viewer. [ virtual public ] 127 | */ 128 | QPaintEngine* OccView::paintEngine() const 129 | { 130 | return 0; 131 | } 132 | 133 | void OccView::paintEvent( QPaintEvent* /*theEvent*/ ) 134 | { 135 | myView->Redraw(); 136 | } 137 | 138 | void OccView::resizeEvent( QResizeEvent* /*theEvent*/ ) 139 | { 140 | if( !myView.IsNull() ) 141 | { 142 | myView->MustBeResized(); 143 | } 144 | } 145 | 146 | void OccView::fitAll( void ) 147 | { 148 | myView->FitAll(); 149 | myView->ZFitAll(); 150 | myView->Redraw(); 151 | } 152 | 153 | void OccView::reset( void ) 154 | { 155 | myView->Reset(); 156 | } 157 | 158 | void OccView::pan( void ) 159 | { 160 | myCurrentMode = CurAction3d_DynamicPanning; 161 | } 162 | 163 | void OccView::zoom( void ) 164 | { 165 | myCurrentMode = CurAction3d_DynamicZooming; 166 | } 167 | 168 | void OccView::rotate( void ) 169 | { 170 | myCurrentMode = CurAction3d_DynamicRotation; 171 | } 172 | 173 | void OccView::mousePressEvent( QMouseEvent* theEvent ) 174 | { 175 | if (theEvent->button() == Qt::LeftButton) 176 | { 177 | onLButtonDown((theEvent->buttons() | theEvent->modifiers()), theEvent->pos()); 178 | } 179 | else if (theEvent->button() == Qt::MidButton) 180 | { 181 | onMButtonDown((theEvent->buttons() | theEvent->modifiers()), theEvent->pos()); 182 | } 183 | else if (theEvent->button() == Qt::RightButton) 184 | { 185 | onRButtonDown((theEvent->buttons() | theEvent->modifiers()), theEvent->pos()); 186 | } 187 | } 188 | 189 | void OccView::mouseReleaseEvent( QMouseEvent* theEvent ) 190 | { 191 | if (theEvent->button() == Qt::LeftButton) 192 | { 193 | onLButtonUp(theEvent->buttons() | theEvent->modifiers(), theEvent->pos()); 194 | } 195 | else if (theEvent->button() == Qt::MidButton) 196 | { 197 | onMButtonUp(theEvent->buttons() | theEvent->modifiers(), theEvent->pos()); 198 | } 199 | else if (theEvent->button() == Qt::RightButton) 200 | { 201 | onRButtonUp(theEvent->buttons() | theEvent->modifiers(), theEvent->pos()); 202 | } 203 | } 204 | 205 | void OccView::mouseMoveEvent( QMouseEvent * theEvent ) 206 | { 207 | onMouseMove(theEvent->buttons(), theEvent->pos()); 208 | } 209 | 210 | void OccView::wheelEvent( QWheelEvent * theEvent ) 211 | { 212 | onMouseWheel(theEvent->buttons(), theEvent->delta(), theEvent->pos()); 213 | } 214 | 215 | void OccView::onLButtonDown( const int /*theFlags*/, const QPoint thePoint ) 216 | { 217 | // Save the current mouse coordinate in min. 218 | myXmin = thePoint.x(); 219 | myYmin = thePoint.y(); 220 | myXmax = thePoint.x(); 221 | myYmax = thePoint.y(); 222 | 223 | } 224 | 225 | void OccView::onMButtonDown( const int /*theFlags*/, const QPoint thePoint ) 226 | { 227 | // Save the current mouse coordinate in min. 228 | myXmin = thePoint.x(); 229 | myYmin = thePoint.y(); 230 | myXmax = thePoint.x(); 231 | myYmax = thePoint.y(); 232 | 233 | if (myCurrentMode == CurAction3d_DynamicRotation) 234 | { 235 | myView->StartRotation(thePoint.x(), thePoint.y()); 236 | } 237 | } 238 | 239 | void OccView::onRButtonDown( const int /*theFlags*/, const QPoint /*thePoint*/ ) 240 | { 241 | 242 | } 243 | 244 | void OccView::onMouseWheel( const int /*theFlags*/, const int theDelta, const QPoint thePoint ) 245 | { 246 | Standard_Integer aFactor = 16; 247 | 248 | Standard_Integer aX = thePoint.x(); 249 | Standard_Integer aY = thePoint.y(); 250 | 251 | if (theDelta > 0) 252 | { 253 | aX += aFactor; 254 | aY += aFactor; 255 | } 256 | else 257 | { 258 | aX -= aFactor; 259 | aY -= aFactor; 260 | } 261 | 262 | myView->Zoom(thePoint.x(), thePoint.y(), aX, aY); 263 | } 264 | 265 | void OccView::addItemInPopup( QMenu* /*theMenu*/ ) 266 | { 267 | } 268 | 269 | void OccView::popup( const int /*x*/, const int /*y*/ ) 270 | { 271 | } 272 | 273 | void OccView::onLButtonUp( const int theFlags, const QPoint thePoint ) 274 | { 275 | // Hide the QRubberBand 276 | if (myRectBand) 277 | { 278 | myRectBand->hide(); 279 | } 280 | 281 | // Ctrl for multi selection. 282 | if (thePoint.x() == myXmin && thePoint.y() == myYmin) 283 | { 284 | if (theFlags & Qt::ControlModifier) 285 | { 286 | multiInputEvent(thePoint.x(), thePoint.y()); 287 | } 288 | else 289 | { 290 | inputEvent(thePoint.x(), thePoint.y()); 291 | } 292 | } 293 | 294 | } 295 | 296 | void OccView::onMButtonUp( const int /*theFlags*/, const QPoint thePoint ) 297 | { 298 | if (thePoint.x() == myXmin && thePoint.y() == myYmin) 299 | { 300 | panByMiddleButton(thePoint); 301 | } 302 | } 303 | 304 | void OccView::onRButtonUp( const int /*theFlags*/, const QPoint thePoint ) 305 | { 306 | popup(thePoint.x(), thePoint.y()); 307 | } 308 | 309 | void OccView::onMouseMove( const int theFlags, const QPoint thePoint ) 310 | { 311 | // Draw the rubber band. 312 | if (theFlags & Qt::LeftButton) 313 | { 314 | drawRubberBand(myXmin, myYmin, thePoint.x(), thePoint.y()); 315 | 316 | dragEvent(thePoint.x(), thePoint.y()); 317 | } 318 | 319 | // Ctrl for multi selection. 320 | if (theFlags & Qt::ControlModifier) 321 | { 322 | multiMoveEvent(thePoint.x(), thePoint.y()); 323 | } 324 | else 325 | { 326 | moveEvent(thePoint.x(), thePoint.y()); 327 | } 328 | 329 | // Middle button. 330 | if (theFlags & Qt::MidButton) 331 | { 332 | switch (myCurrentMode) 333 | { 334 | case CurAction3d_DynamicRotation: 335 | myView->Rotation(thePoint.x(), thePoint.y()); 336 | break; 337 | 338 | case CurAction3d_DynamicZooming: 339 | myView->Zoom(myXmin, myYmin, thePoint.x(), thePoint.y()); 340 | break; 341 | 342 | case CurAction3d_DynamicPanning: 343 | myView->Pan(thePoint.x() - myXmax, myYmax - thePoint.y()); 344 | myXmax = thePoint.x(); 345 | myYmax = thePoint.y(); 346 | break; 347 | 348 | default: 349 | break; 350 | } 351 | } 352 | 353 | } 354 | 355 | void OccView::dragEvent( const int x, const int y ) 356 | { 357 | myContext->Select(myXmin, myYmin, x, y, myView, Standard_True); 358 | 359 | emit selectionChanged(); 360 | } 361 | 362 | void OccView::multiDragEvent( const int x, const int y ) 363 | { 364 | myContext->ShiftSelect(myXmin, myYmin, x, y, myView, Standard_True); 365 | 366 | emit selectionChanged(); 367 | 368 | } 369 | 370 | void OccView::inputEvent( const int x, const int y ) 371 | { 372 | Q_UNUSED(x); 373 | Q_UNUSED(y); 374 | 375 | myContext->Select(Standard_True); 376 | 377 | emit selectionChanged(); 378 | } 379 | 380 | void OccView::multiInputEvent( const int x, const int y ) 381 | { 382 | Q_UNUSED(x); 383 | Q_UNUSED(y); 384 | 385 | myContext->ShiftSelect(Standard_True); 386 | 387 | emit selectionChanged(); 388 | } 389 | 390 | void OccView::moveEvent( const int x, const int y ) 391 | { 392 | myContext->MoveTo(x, y, myView, Standard_True); 393 | } 394 | 395 | void OccView::multiMoveEvent( const int x, const int y ) 396 | { 397 | myContext->MoveTo(x, y, myView, Standard_True); 398 | } 399 | 400 | void OccView::drawRubberBand( const int minX, const int minY, const int maxX, const int maxY ) 401 | { 402 | QRect aRect; 403 | 404 | // Set the rectangle correctly. 405 | (minX < maxX) ? (aRect.setX(minX)) : (aRect.setX(maxX)); 406 | (minY < maxY) ? (aRect.setY(minY)) : (aRect.setY(maxY)); 407 | 408 | aRect.setWidth(abs(maxX - minX)); 409 | aRect.setHeight(abs(maxY - minY)); 410 | 411 | if (!myRectBand) 412 | { 413 | myRectBand = new QRubberBand(QRubberBand::Rectangle, this); 414 | 415 | // setStyle is important, set to windows style will just draw 416 | // rectangle frame, otherwise will draw a solid rectangle. 417 | myRectBand->setStyle(QStyleFactory::create("windows")); 418 | } 419 | 420 | myRectBand->setGeometry(aRect); 421 | myRectBand->show(); 422 | } 423 | 424 | void OccView::panByMiddleButton( const QPoint& thePoint ) 425 | { 426 | Standard_Integer aCenterX = 0; 427 | Standard_Integer aCenterY = 0; 428 | 429 | QSize aSize = size(); 430 | 431 | aCenterX = aSize.width() / 2; 432 | aCenterY = aSize.height() / 2; 433 | 434 | myView->Pan(aCenterX - thePoint.x(), thePoint.y() - aCenterY); 435 | } 436 | -------------------------------------------------------------------------------- /occView.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Shing Liu All Rights Reserved. 3 | * 4 | * File : OccView.h 5 | * Author : Shing Liu(eryar@163.com) 6 | * Date : 2018-01-09 21:00 7 | * Version : OpenCASCADE7.2.0 & Qt5.7.1 8 | * 9 | * Description : Adapte OpenCASCADE view for Qt. 10 | */ 11 | 12 | #ifndef _OCCVIEW_H_ 13 | #define _OCCVIEW_H_ 14 | 15 | #include 16 | 17 | #include 18 | 19 | class QMenu; 20 | class QRubberBand; 21 | 22 | //! Adapted a QWidget for OpenCASCADE viewer. 23 | class OccView : public QWidget 24 | { 25 | Q_OBJECT 26 | 27 | public: 28 | //! mouse actions. 29 | enum CurrentAction3d 30 | { 31 | CurAction3d_Nothing, 32 | CurAction3d_DynamicZooming, 33 | CurAction3d_WindowZooming, 34 | CurAction3d_DynamicPanning, 35 | CurAction3d_GlobalPanning, 36 | CurAction3d_DynamicRotation 37 | }; 38 | 39 | public: 40 | //! constructor. 41 | OccView(QWidget* parent); 42 | 43 | const Handle(AIS_InteractiveContext)& getContext() const; 44 | 45 | signals: 46 | void selectionChanged(void); 47 | 48 | public slots: 49 | //! operations for the view. 50 | void pan(void); 51 | void fitAll(void); 52 | void reset(void); 53 | void zoom(void); 54 | void rotate(void); 55 | 56 | protected: 57 | virtual QPaintEngine* paintEngine() const; 58 | 59 | // Paint events. 60 | virtual void paintEvent(QPaintEvent* theEvent); 61 | virtual void resizeEvent(QResizeEvent* theEvent); 62 | 63 | // Mouse events. 64 | virtual void mousePressEvent(QMouseEvent* theEvent); 65 | virtual void mouseReleaseEvent(QMouseEvent* theEvent); 66 | virtual void mouseMoveEvent(QMouseEvent * theEvent); 67 | virtual void wheelEvent(QWheelEvent * theEvent); 68 | 69 | // Button events. 70 | virtual void onLButtonDown(const int theFlags, const QPoint thePoint); 71 | virtual void onMButtonDown(const int theFlags, const QPoint thePoint); 72 | virtual void onRButtonDown(const int theFlags, const QPoint thePoint); 73 | virtual void onMouseWheel(const int theFlags, const int theDelta, const QPoint thePoint); 74 | virtual void onLButtonUp(const int theFlags, const QPoint thePoint); 75 | virtual void onMButtonUp(const int theFlags, const QPoint thePoint); 76 | virtual void onRButtonUp(const int theFlags, const QPoint thePoint); 77 | virtual void onMouseMove(const int theFlags, const QPoint thePoint); 78 | 79 | // Popup menu. 80 | virtual void addItemInPopup(QMenu* theMenu); 81 | 82 | protected: 83 | void init(void); 84 | void popup(const int x, const int y); 85 | void dragEvent(const int x, const int y); 86 | void inputEvent(const int x, const int y); 87 | void moveEvent(const int x, const int y); 88 | void multiMoveEvent(const int x, const int y); 89 | void multiDragEvent(const int x, const int y); 90 | void multiInputEvent(const int x, const int y); 91 | void drawRubberBand(const int minX, const int minY, const int maxX, const int maxY); 92 | void panByMiddleButton(const QPoint& thePoint); 93 | 94 | private: 95 | 96 | //! the occ viewer. 97 | Handle(V3d_Viewer) myViewer; 98 | 99 | //! the occ view. 100 | Handle(V3d_View) myView; 101 | 102 | //! the occ context. 103 | Handle(AIS_InteractiveContext) myContext; 104 | 105 | //! save the mouse position. 106 | Standard_Integer myXmin; 107 | Standard_Integer myYmin; 108 | Standard_Integer myXmax; 109 | Standard_Integer myYmax; 110 | 111 | //! the mouse current mode. 112 | CurrentAction3d myCurrentMode; 113 | 114 | //! save the degenerate mode state. 115 | Standard_Boolean myDegenerateModeIsOn; 116 | 117 | //! rubber rectangle for the mouse selection. 118 | QRubberBand* myRectBand; 119 | 120 | }; 121 | 122 | #endif // _OCCVIEW_H_ 123 | -------------------------------------------------------------------------------- /occqt.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/FitAll.png 4 | Resources/Home.png 5 | Resources/Pan.png 6 | Resources/Rotate.png 7 | Resources/Zoom.png 8 | Resources/cone.png 9 | Resources/cylinder.png 10 | Resources/sphere.png 11 | Resources/box.png 12 | Resources/torus.png 13 | Resources/chamfer.png 14 | Resources/fillet.png 15 | Resources/lamp.png 16 | Resources/common.png 17 | Resources/cut.png 18 | Resources/fuse.png 19 | Resources/extrude.png 20 | Resources/loft.png 21 | Resources/revolve.png 22 | Resources/helix.png 23 | 24 | 25 | -------------------------------------------------------------------------------- /occt.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | [{(float)x} {(float)y}] 5 | 6 | 7 | 8 | 9 | [{(float)cood.x} {(float)cood.y}] 10 | 11 | 12 | [{(float)x} {(float)y} {(float)z}] 13 | 14 | 15 | 16 | 17 | [{(float)coord.x} {(float)coord.y} {(float)coord.z}] 18 | 19 | 20 | [{v[0]} {v[1]}] 21 | 22 | 23 | [{v[0]} {v[1]} {v[2]}] 24 | 25 | 26 | [{v[0]} {v[1]} {v[2]} {v[3]}] 27 | 28 | 29 | 30 | [{(float)matrix[0][0]} {(float)matrix[0][1]}], [{(float)matrix[1][0]} {(float)matrix[1][1]}] 31 | 32 | 33 | 34 | 35 | ((NCollection_Vec4<$T1>*)myMat)[0] 36 | ((NCollection_Vec4<$T1>*)myMat)[1] 37 | ((NCollection_Vec4<$T1>*)myMat)[2] 38 | ((NCollection_Vec4<$T1>*)myMat)[3] 39 | 40 | 41 | 42 | NULL 43 | [cnt={entity->count}] 44 | 45 | *entity 46 | 47 | 48 | 49 | NULL 50 | {(void*)entity} [cnt={entity->count}] 51 | 52 | *((NCollection_Handle<$T1>::Ptr*)entity)->myPtr 53 | 54 | 55 | 56 | NULL 57 | {(void*)entity} [cnt={entity->count} {*entity}] 58 | 59 | (opencascade::handle<$T1>::element_type*)entity 60 | 61 | 62 | 63 | {mylength}: {mystring,s} 64 | 65 | mystring,s8 66 | 67 | 68 | 69 | {myString.mylength}: {myString.mystring,s} 70 | 71 | 72 | {myLength}: {myString,s} 73 | 74 | 75 | {mylength}: {(wchar_t *)mystring,su} 76 | 77 | 78 | {myString.mylength}: {(wchar_t *)myString.mystring,su} 79 | 80 | 81 | TColStd_PackedMapOfInteger [{myExtent}] 82 | 83 | 84 | NCollection_Vector [{myLength}] 85 | 86 | 87 | myData->Length 88 | *($T1*)((char*)myData->DataPtr + $i * myItemSize) 89 | 90 | 91 | myLength 92 | *($T1*)((char*)myData->DataPtr + $i * myItemSize) 93 | 94 | 95 | 96 | 97 | NCollection_Array1 [{myUpperBound - myLowerBound + 1}] 98 | 99 | myUpperBound - myLowerBound + 1 100 | 101 | myUpperBound - myLowerBound + 1 102 | (myData) + myLowerBound 103 | 104 | 105 | 106 | 107 | NCollection_List [{myLength}] 108 | 109 | 110 | myLength 111 | myFirst 112 | myNext 113 | *($T1*)(sizeof(NCollection_ListNode) + ((char *)this)) 114 | 115 | 116 | 117 | 118 | NCollection_Sequence [{mySize}] 119 | 120 | 121 | mySize 122 | myFirstItem 123 | myNext 124 | *($T1*)(sizeof(NCollection_SeqNode) + ((char *)this)) 125 | 126 | 127 | 128 | 129 | 130 | VOID 131 | 132 | Center: [{(float)myCenter[0]} {(float)myCenter[1]}], hSize: [{(float)myHSize[0]} {(float)myHSize[1]}] 133 | 134 | 135 | 136 | 137 | VOID 138 | 139 | Center: [{(float)myCenter[0]} {(float)myCenter[1]} {(float)myCenter[2]}], hSize: [{(float)myHSize[0]} {(float)myHSize[1]} {(float)myHSize[2]}] 140 | 141 | 142 | 143 | NULL 144 | [:{myLabelNode->myTag}] 145 | 146 | *myLabelNode 147 | 148 | 149 | 150 | [:{myTag}] 151 | 152 | * myBrother 153 | * myFirstChild 154 | myFirstAttribute 155 | 156 | 157 | 158 | NULL 159 | 160 | [transaction={((TDF_Attribute*)entity)->myTransaction}] 161 | 162 | 163 | 164 | (TDF_Attribute*)entity 165 | 166 | 167 | 168 | [{myGlVerMajor}.{myGlVerMinor}] 169 | 170 | 171 | 172 | 173 | empty 174 | {{size = {myUpperBound - myLowerBound + 1}}} 175 | 176 | myUpperBound - myLowerBound + 1 177 | 178 | myUpperBound - myLowerBound + 1 179 | (Standard_Integer*)(myStart) + myLowerBound 180 | 181 | 182 | 183 | 184 | 185 | empty 186 | {{size = {myUpperBound - myLowerBound + 1}}} 187 | 188 | myUpperBound - myLowerBound + 1 189 | 190 | myUpperBound - myLowerBound + 1 191 | (Standard_Real*)(myStart) + myLowerBound 192 | 193 | 194 | 195 | 196 | 197 | 198 | empty 199 | extent = {(myUpperColumn-myLowerColumn+1) * (myUpperRow-myLowerRow+1)} 200 | 201 | 202 | 203 | 204 | 205 | {{current = {myValue}}} 206 | 207 | 208 | this 209 | (TColStd_ListNodeOfListOfInteger*)myNext 210 | this->myValue 211 | 212 | 213 | 214 | 215 | 216 | empty 217 | 218 | (TColStd_ListNodeOfListOfInteger*)(myFirst) 219 | 220 | 221 | 222 | 223 | {{current = {myValue}}} 224 | 225 | 226 | this 227 | (TColStd_ListNodeOfListOfReal*)myNext 228 | this->myValue 229 | 230 | 231 | 232 | 233 | 234 | empty 235 | 236 | (TColStd_ListNodeOfListOfReal*)(myFirst) 237 | 238 | 239 | 240 | 241 | empty 242 | 243 | (BRep_ListNodeOfListOfCurveRepresentation*)(myFirst) 244 | 245 | 246 | 247 | 248 | {myOrient} {myTShape} loc={myLocation} 249 | 250 | 251 | 252 | subshapes={myShapes} flags={myFlags} 253 | 254 | 255 | 256 | {{{myIndex} {myParameter}}} 257 | 258 | 259 | 260 | edge={myEdge} orig={myOriginalEdge} pave1={myPave1} pave2={myPave2} extpaves={myExtPaves} 261 | 262 | 263 | 264 | --------------------------------------------------------------------------------