-
Notifications
You must be signed in to change notification settings - Fork 11
/
occQt.cpp
209 lines (156 loc) · 5.7 KB
/
occQt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
IsoAlgo3d - PCF format 3d visualization tool.
Copyright (C) 2016 Shing Liu
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2 of the License, or any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Copy of the GNU General Public License is in LICENSE.txt and
on <http://www.gnu.org/licenses/>.
*/
#include "occQt.h"
#include "occView.h"
#include "IsoPcfReader.h"
#include <QToolBar>
#include <QTreeView>
#include <QMessageBox>
#include <QFileDialog>
#include <QDockWidget>
#include <QProgressBar>
#include <gp_Ax2.hxx>
#include <gp_Circ.hxx>
#include <GC_MakeArcOfCircle.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepOffsetAPI_MakePipe.hxx>
#include <AIS_Shape.hxx>
occQt::occQt(QWidget *parent)
: QMainWindow(parent)
, myProgressBar(new QProgressBar())
{
ui.setupUi(this);
myOccView = new OccView(this);
setCentralWidget(myOccView);
createActions();
createMenus();
createToolBars();
}
occQt::~occQt()
{
}
void occQt::createActions( void )
{
connect(ui.actionLoadPCF, SIGNAL(triggered()), this, SLOT(loadPcf()));
connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close()));
connect(ui.actionZoom, SIGNAL(triggered()), myOccView, SLOT(zoom()));
connect(ui.actionPan, SIGNAL(triggered()), myOccView, SLOT(pan()));
connect(ui.actionRotate, SIGNAL(triggered()), myOccView, SLOT(rotate()));
connect(ui.actionHome, SIGNAL(triggered()), myOccView, SLOT(reset()));
connect(ui.actionFitAll, SIGNAL(triggered()), myOccView, SLOT(fitAll()));
connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(about()));
}
void occQt::createMenus( void )
{
}
void occQt::createToolBars( void )
{
myToolbar = addToolBar(tr("IsoAlgo3d"));
myToolbar->addAction(ui.actionLoadPCF);
myToolbar->addSeparator();
myToolbar->addAction(ui.actionZoom);
myToolbar->addAction(ui.actionPan);
myToolbar->addAction(ui.actionRotate);
myToolbar->addSeparator();
myToolbar->addAction(ui.actionHome);
myToolbar->addAction(ui.actionFitAll);
myToolbar->addSeparator();
myToolbar->addAction(ui.actionAbout);
}
void occQt::about()
{
QMessageBox::about(this, tr("About IsoAlgo3d"),
tr("<h2>IsoAlgo3d - PCF format 3d visualization tool.</h2>"
"<p>Copyright © 2016 Shing Liu"
"<p>Feedback: Shing Liu([email protected])"
"<p>Version: 1.0"));
}
void occQt::loadPcf()
{
QStringList aPcfFiles = QFileDialog::getOpenFileNames(this, tr("Load PCF File"), "", tr("PCF Files(*.pcf)"));
// show progress bar when building the piping model.
this->statusBar()->addWidget(myProgressBar);
myProgressBar->setMinimum(0);
myProgressBar->setMaximum(aPcfFiles.size());
for (int i = 0; i < aPcfFiles.size(); ++i)
{
myProgressBar->setValue(i + 1);
readPcfFile(aPcfFiles.at(i));
}
// hide the progress bar when finished.
this->statusBar()->removeWidget(myProgressBar);
}
void occQt::readPcfFile(const QString& thePcfName)
{
if (thePcfName.isEmpty())
{
return;
}
IsoAlgo::IsoPcfReader aPcfReader(thePcfName.toStdString());
const IsoAlgo::IsoPipeline& aPipeline = aPcfReader.GetPipeline();
for (int i = 0; i < aPipeline.GetComponentCount(); ++i)
{
const IsoAlgo::IsoComponent* aComponent = aPipeline.GetComponent(i);
TopoDS_Shape aTopoShape = buildShape(aComponent);
if (aTopoShape.IsNull() || myOccView->getContext().IsNull())
{
continue;
}
Handle(AIS_Shape) anAisShape = new AIS_Shape(aTopoShape);
myOccView->getContext()->Display(anAisShape, false);
}
myOccView->fitAll();
}
TopoDS_Shape occQt::buildShape(const IsoAlgo::IsoComponent *theComponent)
{
TopoDS_Shape aComponentShape;
if (theComponent->GetType() == "PIPE")
{
buildPipe(theComponent, aComponentShape);
}
else if (theComponent->GetType() == "ELBOW")
{
buildElbow(theComponent, aComponentShape);
}
return aComponentShape;
}
void occQt::buildPipe(const IsoAlgo::IsoComponent *theComponent, TopoDS_Shape &theShape)
{
Standard_Real aDiameter = theComponent->GetArrivePoint().GetDiameter();
gp_Pnt aArrivePoint = theComponent->GetArrivePoint().GetPosition();
gp_Pnt aLeavePoint = theComponent->GetLeavePoint().GetPosition();
gp_Vec aVector(aArrivePoint, aLeavePoint);
gp_Ax2 anAxis(aArrivePoint, gp_Dir(aVector));
theShape = BRepPrimAPI_MakeCylinder(anAxis, aDiameter * 0.5, aVector.Magnitude()).Shape();
}
void occQt::buildElbow(const IsoAlgo::IsoComponent *theComponent, TopoDS_Shape &theShape)
{
gp_Pnt aArrivePoint = theComponent->GetArrivePoint().GetPosition();
gp_Pnt aLeavePoint = theComponent->GetLeavePoint().GetPosition();
gp_Pnt aCentrePoint = theComponent->GetCentrePoint().GetPosition();
gp_Vec aVector(aArrivePoint, aCentrePoint);
gp_Ax2 anAxis(aArrivePoint, gp_Dir(aVector));
GC_MakeArcOfCircle anArcMaker(aArrivePoint, aVector, aLeavePoint);
TopoDS_Shape aProfile = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, theComponent->GetArrivePoint().GetDiameter()/2.0)).Shape();
TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anArcMaker.Value()).Edge();
TopoDS_Wire aSpine = BRepBuilderAPI_MakeWire(anEdge).Wire();
BRepOffsetAPI_MakePipe aPipeMaker(aSpine, aProfile);
if (aPipeMaker.IsDone())
{
theShape = aPipeMaker.Shape();
}
}