a2176e65 |
1 | // Copyright (c) 2020 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of the examples of the Open CASCADE Technology software library. |
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 SOFTWARE |
21 | |
22 | #include "ApplicationCommon.h" |
23 | |
24 | #include <Standard_WarningsDisable.hxx> |
25 | #include <QApplication> |
26 | #include <QDir> |
27 | #include <QFile> |
28 | #include <QFont> |
29 | #include <QFrame> |
30 | #include <QGroupBox> |
a2176e65 |
31 | #include <QMap> |
32 | #include <QMdiArea> |
33 | #include <QMdiSubWindow> |
34 | #include <QMenuBar> |
35 | #include <QMessageBox> |
36 | #include <QPair> |
37 | #include <QSplitter> |
38 | #include <QStatusBar> |
39 | #include <QtGlobal> |
40 | #include <QHBoxLayout> |
41 | #include <QVBoxLayout> |
42 | #include <QWidget> |
8833fd4d |
43 | #include <QDomDocument> |
44 | #include <QDomAttr> |
a2176e65 |
45 | #include <Standard_WarningsRestore.hxx> |
46 | |
47 | #include <OpenGl_GraphicDriver.hxx> |
48 | #include <OSD_Environment.hxx> |
49 | |
50 | #include <stdlib.h> |
51 | #include <memory> |
52 | |
53 | ApplicationCommonWindow::ApplicationCommonWindow (ApplicationType theCategory) |
54 | : QMainWindow (nullptr), |
8833fd4d |
55 | myAppType(theCategory), |
a2176e65 |
56 | myStdToolBar (nullptr), |
57 | myViewBar (nullptr), |
58 | myCasCadeBar (nullptr), |
59 | myFilePopup (nullptr), |
60 | myCategoryPopup (nullptr) |
61 | { |
8833fd4d |
62 | ALL_CATEGORIES[AppType_Geometry] = "Geometry"; |
63 | ALL_CATEGORIES[AppType_Topology] = "Topology"; |
64 | ALL_CATEGORIES[AppType_Triangulation] = "Triangulation"; |
65 | ALL_CATEGORIES[AppType_DataExchange] = "DataExchange"; |
66 | ALL_CATEGORIES[AppType_Ocaf] = "OCAF"; |
67 | ALL_CATEGORIES[AppType_Viewer3d] = "3D viewer"; |
68 | ALL_CATEGORIES[AppType_Viewer2d] = "2D Viewer"; |
69 | |
a2176e65 |
70 | mySampleMapper = new QSignalMapper(this); |
71 | myExchangeMapper = new QSignalMapper(this); |
72 | myOcafMapper = new QSignalMapper(this); |
73 | myViewer3dMapper = new QSignalMapper(this); |
74 | myViewer2dMapper = new QSignalMapper(this); |
75 | |
76 | myCategoryMapper = new QSignalMapper(this); |
77 | |
8833fd4d |
78 | connect(mySampleMapper, SIGNAL(mapped(const QString &)), this, SLOT(onProcessSample(const QString &))); |
79 | connect(myExchangeMapper, SIGNAL(mapped(const QString &)), this, SLOT(onProcessExchange(const QString &))); |
80 | connect(myOcafMapper, SIGNAL(mapped(const QString &)), this, SLOT(onProcessOcaf(const QString &))); |
81 | connect(myViewer3dMapper, SIGNAL(mapped(const QString &)), this, SLOT(onProcessViewer3d(const QString &))); |
82 | connect(myViewer2dMapper, SIGNAL(mapped(const QString &)), this, SLOT(onProcessViewer2d(const QString &))); |
a2176e65 |
83 | |
8833fd4d |
84 | connect(myCategoryMapper, SIGNAL(mapped(const QString &)), this, SLOT(onChangeCategory(const QString &))); |
a2176e65 |
85 | |
86 | setFocusPolicy(Qt::StrongFocus); |
87 | |
88 | QFont aCodeViewFont; |
89 | aCodeViewFont.setFamily("Courier"); |
90 | aCodeViewFont.setFixedPitch(true); |
91 | aCodeViewFont.setPointSize(10); |
92 | |
93 | QGroupBox* aCodeFrame = new QGroupBox(tr("Sample code")); |
94 | QVBoxLayout* aCodeLayout = new QVBoxLayout(aCodeFrame); |
95 | aCodeLayout->setContentsMargins(3, 3, 3, 3); |
96 | myCodeView = new QTextEdit(aCodeFrame); |
97 | aCodeLayout->addWidget(myCodeView); |
98 | myCodeView->setDocumentTitle("Code"); |
99 | myCodeView->setLineWrapMode(QTextEdit::NoWrap); |
100 | myCodeView->setReadOnly(true); |
101 | myCodeView->setFont(aCodeViewFont); |
102 | myCodeViewHighlighter = new OcctHighlighter(myCodeView->document()); |
103 | |
104 | QGroupBox* aResultFrame = new QGroupBox(tr("Output")); |
105 | QVBoxLayout* aResultLayout = new QVBoxLayout(aResultFrame); |
106 | aResultLayout->setContentsMargins(3, 3, 3, 3); |
107 | myResultView = new QTextEdit(aResultFrame); |
108 | aResultLayout->addWidget(myResultView); |
109 | myResultView->setDocumentTitle("Output"); |
110 | myResultView->setReadOnly(true); |
111 | myResultView->setFont(aCodeViewFont); |
112 | |
113 | QSplitter* aCodeResultSplitter = new QSplitter(Qt::Vertical); |
114 | aCodeResultSplitter->addWidget(aCodeFrame); |
115 | aCodeResultSplitter->addWidget(aResultFrame); |
116 | |
117 | myDocument3d = createNewDocument(); |
118 | myDocument2d = createNewDocument(); |
119 | |
120 | QFrame* aViewFrame = new QFrame; |
121 | aViewFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
122 | aViewFrame->setLineWidth(3); |
123 | QVBoxLayout* aViewLayout = new QVBoxLayout(aViewFrame); |
124 | aViewLayout->setContentsMargins(0, 0, 0, 0); |
8833fd4d |
125 | myGeomWidget = new GeomWidget(myDocument3d, myDocument2d, aViewFrame); |
a2176e65 |
126 | aViewLayout->addWidget(myGeomWidget); |
8833fd4d |
127 | |
128 | myGeomWidget->setContentsMargins(0, 0, 0, 0); |
a2176e65 |
129 | QSplitter* aGeomTextSplitter = new QSplitter(Qt::Horizontal); |
130 | |
131 | aGeomTextSplitter->addWidget(aViewFrame); |
132 | aGeomTextSplitter->addWidget(aCodeResultSplitter); |
133 | aGeomTextSplitter->setStretchFactor(0, 1); |
134 | aGeomTextSplitter->setStretchFactor(1, 1); |
8833fd4d |
135 | QList<int> aSizeList; |
136 | aSizeList.append(640); |
137 | aSizeList.append(640); |
a2176e65 |
138 | aGeomTextSplitter->setSizes(aSizeList); |
139 | setCentralWidget(aGeomTextSplitter); |
140 | |
8833fd4d |
141 | #include <Standard_WarningsDisable.hxx> |
a2176e65 |
142 | Q_INIT_RESOURCE(Samples); |
8833fd4d |
143 | #include <Standard_WarningsRestore.hxx> |
a2176e65 |
144 | |
145 | TCollection_AsciiString aSampleSourcePach = getSampleSourceDir(); |
146 | myGeometrySamples = new GeometrySamples(aSampleSourcePach, |
147 | myDocument3d->getContext()); |
148 | myTopologySamples = new TopologySamples(aSampleSourcePach, |
149 | myDocument3d->getContext()); |
150 | myTriangulationSamples = new TriangulationSamples(aSampleSourcePach, |
151 | myDocument3d->getContext()); |
152 | myDataExchangeSamples = new DataExchangeSamples(aSampleSourcePach, |
153 | myGeomWidget->Get3dView(), |
154 | myDocument3d->getContext()); |
155 | myOcafSamples = new OcafSamples(aSampleSourcePach, |
156 | myDocument3d->getViewer(), |
157 | myDocument3d->getContext()); |
158 | myViewer3dSamples = new Viewer3dSamples(aSampleSourcePach, |
159 | myGeomWidget->Get3dView(), |
160 | myDocument3d->getContext()); |
161 | myViewer2dSamples = new Viewer2dSamples(aSampleSourcePach, |
162 | myGeomWidget->Get2dView(), |
163 | myDocument2d->getViewer(), |
164 | myDocument2d->getContext()); |
165 | |
8833fd4d |
166 | |
167 | MenuFormXml(":/menus/Geometry.xml", mySampleMapper, myGeometryMenus); |
168 | MenuFormXml(":/menus/Topology.xml", mySampleMapper, myTopologyMenus); |
169 | MenuFormXml(":/menus/Triangulation.xml", mySampleMapper, myTriangulationMenus); |
170 | MenuFormXml(":/menus/DataExchange.xml", myExchangeMapper, myDataExchangeMenus); |
171 | MenuFormXml(":/menus/Ocaf.xml", myOcafMapper, myOcafMenus); |
172 | MenuFormXml(":/menus/Viewer3d.xml", myViewer3dMapper, myViewer3dMenus); |
173 | MenuFormXml(":/menus/Viewer2d.xml", myViewer2dMapper, myViewer2dMenus); |
a2176e65 |
174 | |
175 | onChangeCategory(ALL_CATEGORIES[myAppType]); |
176 | |
177 | resize(1280, 560); |
178 | } |
179 | |
180 | void ApplicationCommonWindow::RebuildMenu() |
181 | { |
182 | menuBar()->clear(); |
183 | |
8833fd4d |
184 | myStdActions[StdActions_FileQuit] = CreateAction("Quit", "CTRL+Q"); |
185 | connect(myStdActions[StdActions_FileQuit], SIGNAL(triggered()), this, SLOT(onCloseAllWindows())); |
186 | myStdActions[StdActions_HelpAbout] = CreateAction("About", "F1", ":/icons/help.png"); |
187 | connect(myStdActions[StdActions_HelpAbout], SIGNAL(triggered()), this, SLOT(onAbout())); |
a2176e65 |
188 | |
189 | // populate a menu with all actions |
190 | myFilePopup = new QMenu(this); |
191 | myFilePopup = menuBar()->addMenu(tr("&File")); |
8833fd4d |
192 | myFilePopup->addAction(myStdActions[StdActions_FileQuit]); |
a2176e65 |
193 | |
194 | myCategoryPopup = new QMenu(this); |
195 | myCategoryPopup = menuBar()->addMenu(tr("&Category")); |
196 | |
8833fd4d |
197 | foreach (ApplicationType aCategory, ALL_CATEGORIES.keys()) |
a2176e65 |
198 | { |
199 | QString aCategoryName = ALL_CATEGORIES.value(aCategory); |
200 | QAction* anAction = myCategoryPopup->addAction(aCategoryName); |
201 | anAction->setText(aCategoryName); |
202 | myCategoryMapper->setMapping(anAction, aCategoryName); |
8833fd4d |
203 | connect(anAction, SIGNAL(triggered()), myCategoryMapper, SLOT(map())); |
a2176e65 |
204 | myCategoryPopup->addAction(anAction); |
205 | myCategoryActions.insert(aCategory, anAction); |
206 | } |
207 | |
8833fd4d |
208 | foreach (QMenu* aSampleMenu, GetCurrentMenus()) |
a2176e65 |
209 | { |
210 | menuBar()->addMenu(aSampleMenu); |
211 | } |
212 | |
213 | // add a help menu |
214 | QMenu* aHelp = new QMenu(this); |
215 | menuBar()->addSeparator(); |
216 | aHelp = menuBar()->addMenu(tr("&Help")); |
8833fd4d |
217 | aHelp->addAction(myStdActions[StdActions_HelpAbout]); |
a2176e65 |
218 | } |
219 | |
220 | Handle(BaseSample) ApplicationCommonWindow::GetCurrentSamples() |
221 | { |
222 | switch (myAppType) |
223 | { |
8833fd4d |
224 | case AppType_Geometry: return myGeometrySamples; |
225 | case AppType_Topology: return myTopologySamples; |
226 | case AppType_Triangulation: return myTriangulationSamples; |
227 | case AppType_DataExchange: return myDataExchangeSamples; |
228 | case AppType_Ocaf: return myOcafSamples; |
229 | case AppType_Viewer2d: return myViewer2dSamples; |
230 | case AppType_Viewer3d: return myViewer3dSamples; |
231 | case AppType_Unknown: |
a2176e65 |
232 | break; |
233 | } |
234 | throw QString("Unknown Application type"); |
235 | } |
236 | |
237 | const QList<QMenu*>& ApplicationCommonWindow::GetCurrentMenus() |
238 | { |
239 | switch (myAppType) |
240 | { |
8833fd4d |
241 | case AppType_Geometry: return myGeometryMenus; |
242 | case AppType_Topology: return myTopologyMenus; |
243 | case AppType_Triangulation: return myTriangulationMenus; |
244 | case AppType_DataExchange: return myDataExchangeMenus; |
245 | case AppType_Ocaf: return myOcafMenus; |
246 | case AppType_Viewer2d: return myViewer2dMenus; |
247 | case AppType_Viewer3d: return myViewer3dMenus; |
248 | case AppType_Unknown: |
a2176e65 |
249 | break; |
250 | } |
251 | throw QString("Unknown Application type"); |
252 | } |
253 | |
254 | DocumentCommon* ApplicationCommonWindow::createNewDocument() |
255 | { |
256 | return new DocumentCommon(this); |
257 | } |
258 | |
259 | void ApplicationCommonWindow::onChangeCategory(const QString& theCategory) |
260 | { |
261 | myAppType = ALL_CATEGORIES.key(theCategory); |
262 | setWindowTitle(ALL_CATEGORIES[myAppType]); |
263 | |
264 | myOcafSamples->ClearExtra(); |
265 | myViewer3dSamples->ClearExtra(); |
266 | myViewer2dSamples->ClearExtra(); |
267 | |
268 | GetCurrentSamples()->Clear(); |
269 | myDocument3d->Clear(); |
270 | myDocument2d->Clear(); |
271 | |
272 | myCodeView->setPlainText(""); |
273 | myResultView->setPlainText(""); |
274 | GetCurrentSamples()->AppendCube(); |
275 | myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects()); |
276 | myGeomWidget->FitAll(); |
277 | |
278 | RebuildMenu(); |
279 | |
280 | switch (myAppType) |
281 | { |
8833fd4d |
282 | case AppType_DataExchange: |
a2176e65 |
283 | { |
284 | myDataExchangeSamples->AppendBottle(); |
285 | myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects()); |
286 | myGeomWidget->Show3d(); |
287 | break; |
288 | } |
8833fd4d |
289 | case AppType_Ocaf: |
a2176e65 |
290 | { |
291 | onProcessOcaf("CreateOcafDocument"); |
292 | myGeomWidget->Show3d(); |
293 | break; |
294 | } |
8833fd4d |
295 | case AppType_Viewer2d: |
a2176e65 |
296 | { |
297 | myGeomWidget->Show2d(); |
298 | break; |
299 | } |
8833fd4d |
300 | case AppType_Viewer3d: |
a2176e65 |
301 | { |
302 | myViewer3dSamples->AppendBottle(); |
303 | myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects()); |
304 | myGeomWidget->Show3d(); |
305 | break; |
306 | } |
8833fd4d |
307 | case AppType_Geometry: |
308 | case AppType_Topology: |
309 | case AppType_Triangulation: |
310 | case AppType_Unknown: |
a2176e65 |
311 | { |
312 | break; |
313 | } |
314 | } |
315 | } |
316 | |
317 | void ApplicationCommonWindow::onAbout() |
318 | { |
319 | QMessageBox::information(this, tr("OCCT Overview"), |
320 | tr("Qt based application to study OpenCASCADE Technology"), |
321 | tr("Ok"), QString::null, QString::null, 0, 0); |
322 | } |
323 | |
324 | TCollection_AsciiString ApplicationCommonWindow::getSampleSourceDir() |
325 | { |
326 | TCollection_AsciiString aSampleSourceDir = OSD_Environment("CSF_OCCTOverviewSampleCodePath").Value(); |
327 | if (aSampleSourceDir.IsEmpty()) |
328 | { |
329 | TCollection_AsciiString aCasRoot = OSD_Environment("CASROOT").Value(); |
330 | if (!aCasRoot.IsEmpty()) |
331 | { |
332 | aSampleSourceDir = aCasRoot + "/samples/OCCTOverview/code"; |
333 | } |
334 | } |
335 | return aSampleSourceDir; |
336 | } |
337 | |
8833fd4d |
338 | QAction* ApplicationCommonWindow::CreateAction (const QString& theActionName, |
a2176e65 |
339 | const QString& theShortcut, |
340 | const QString& theIconName) |
341 | { |
342 | QAction* aAction(NULL); |
343 | if (theIconName.isEmpty()) |
344 | { |
345 | aAction = new QAction(theActionName, this); |
346 | } |
347 | else |
348 | { |
349 | QPixmap aIcon = QPixmap(theIconName); |
350 | aAction = new QAction(aIcon, theActionName, this); |
351 | } |
352 | aAction->setToolTip(theActionName); |
353 | aAction->setStatusTip(theActionName); |
354 | aAction->setShortcut(theShortcut); |
8833fd4d |
355 | |
a2176e65 |
356 | return aAction; |
357 | } |
358 | |
359 | template <typename PointerToMemberFunction> |
360 | QAction* ApplicationCommonWindow::CreateSample (PointerToMemberFunction theHandlerMethod, |
361 | const char* theActionName) |
362 | { |
8833fd4d |
363 | QAction* anAction = new QAction(QObject::tr(theActionName), this); |
364 | connect(anAction, SIGNAL(triggered()), this, SLOT(theHandlerMethod())); |
365 | return anAction; |
a2176e65 |
366 | } |
367 | |
368 | void ApplicationCommonWindow::resizeEvent(QResizeEvent* e) |
369 | { |
370 | QMainWindow::resizeEvent(e); |
371 | statusBar()->setSizeGripEnabled(!isMaximized()); |
372 | } |
373 | |
374 | void ApplicationCommonWindow::onProcessSample(const QString& theSampleName) |
375 | { |
376 | QApplication::setOverrideCursor(Qt::WaitCursor); |
377 | setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName); |
378 | GetCurrentSamples()->Process(theSampleName.toUtf8().data()); |
379 | myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects()); |
380 | myDocument2d->SetObjects(GetCurrentSamples()->Get2dObjects()); |
381 | myCodeView->setPlainText(GetCurrentSamples()->GetCode().ToCString()); |
382 | myResultView->setPlainText(GetCurrentSamples()->GetResult().ToCString()); |
383 | myGeomWidget->FitAll(); |
384 | QApplication::restoreOverrideCursor(); |
385 | } |
386 | |
387 | void ApplicationCommonWindow::onProcessExchange(const QString& theSampleName) |
388 | { |
389 | setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName); |
390 | int aMode = 0; |
391 | QString aFileName = selectFileName(theSampleName, getDataExchangeDialog(theSampleName), aMode); |
392 | if (aFileName.isEmpty()) |
393 | { |
394 | return; |
395 | } |
396 | |
397 | QApplication::setOverrideCursor(Qt::WaitCursor); |
398 | myDataExchangeSamples->SetFileName(aFileName.toUtf8().data()); |
399 | myDataExchangeSamples->SetStepType(static_cast<STEPControl_StepModelType>(aMode)); |
400 | myDataExchangeSamples->Process(theSampleName.toUtf8().data()); |
401 | myDocument3d->SetObjects(myDataExchangeSamples->Get3dObjects()); |
402 | myDocument2d->SetObjects(myDataExchangeSamples->Get2dObjects()); |
403 | myCodeView->setPlainText(myDataExchangeSamples->GetCode().ToCString()); |
404 | myResultView->setPlainText(myDataExchangeSamples->GetResult().ToCString()); |
405 | myGeomWidget->FitAll(); |
406 | QApplication::restoreOverrideCursor(); |
407 | } |
408 | |
409 | void ApplicationCommonWindow::onProcessOcaf(const QString& theSampleName) |
410 | { |
411 | setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName); |
412 | |
413 | if (theSampleName.indexOf("Dialog") == 0) |
414 | { |
415 | int aMode = 0; // not used |
416 | QString aFileName = selectFileName(theSampleName, getOcafDialog(theSampleName), aMode); |
417 | if (aFileName.isEmpty()) |
418 | { |
419 | return; |
420 | } |
421 | myOcafSamples->SetFileName(aFileName.toUtf8().data()); |
422 | } |
423 | QApplication::setOverrideCursor(Qt::WaitCursor); |
424 | myOcafSamples->Process(theSampleName.toUtf8().data()); |
425 | myDocument2d->SetObjects(myOcafSamples->Get2dObjects()); |
426 | myCodeView->setPlainText(myOcafSamples->GetCode().ToCString()); |
427 | myResultView->setPlainText(myOcafSamples->GetResult().ToCString()); |
428 | QApplication::restoreOverrideCursor(); |
429 | } |
430 | |
431 | void ApplicationCommonWindow::onProcessViewer3d(const QString& theSampleName) |
432 | { |
433 | setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName); |
434 | |
435 | QApplication::setOverrideCursor(Qt::WaitCursor); |
436 | myViewer3dSamples->Process(theSampleName.toUtf8().data()); |
437 | myCodeView->setPlainText(myViewer3dSamples->GetCode().ToCString()); |
438 | myResultView->setPlainText(myViewer3dSamples->GetResult().ToCString()); |
439 | myGeomWidget->FitAll(); |
440 | QApplication::restoreOverrideCursor(); |
441 | } |
442 | |
443 | void ApplicationCommonWindow::onProcessViewer2d(const QString& theSampleName) |
444 | { |
445 | setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName); |
446 | |
447 | Standard_Boolean anIsFileSample = Viewer2dSamples::IsFileSample(theSampleName.toUtf8().data()); |
448 | QString aFileName; |
449 | if (anIsFileSample) |
450 | { |
451 | int aMode = 0; // not used |
452 | aFileName = selectFileName(theSampleName, getOcafDialog(theSampleName), aMode); |
453 | if (aFileName.isEmpty()) |
454 | { |
455 | return; |
456 | } |
457 | |
458 | myViewer2dSamples->SetFileName(aFileName.toUtf8().data()); |
459 | } |
460 | if (!anIsFileSample || (anIsFileSample && !aFileName.isEmpty())) |
461 | { |
462 | QApplication::setOverrideCursor(Qt::WaitCursor); |
463 | myViewer2dSamples->Process(theSampleName.toUtf8().data()); |
464 | if (!Viewer2dSamples::IsShadedSample(theSampleName.toUtf8().data())) |
465 | { |
466 | myDocument2d->SetObjects(myViewer2dSamples->Get2dObjects(), Standard_False); |
467 | } |
468 | else |
469 | { |
470 | myDocument2d->SetObjects(myViewer2dSamples->Get2dObjects(), Standard_True); |
471 | } |
472 | myCodeView->setPlainText(myViewer2dSamples->GetCode().ToCString()); |
473 | myResultView->setPlainText(myViewer2dSamples->GetResult().ToCString()); |
474 | myGeomWidget->Show2d(); |
475 | QApplication::restoreOverrideCursor(); |
476 | } |
477 | else |
478 | { |
479 | myResultView->setPlainText("No file selected!"); |
480 | } |
481 | } |
482 | |
483 | QString ApplicationCommonWindow::selectFileName(const QString& theSampleName, |
484 | TranslateDialog* theDialog, int& theMode) |
485 | { |
486 | Q_UNUSED(theSampleName) |
487 | |
488 | std::shared_ptr<TranslateDialog> aDialog(theDialog); |
489 | |
490 | int ret = aDialog->exec(); |
491 | theMode = aDialog->getMode(); |
492 | |
493 | qApp->processEvents(); |
494 | |
495 | QString aFilename; |
496 | QStringList aFileNameList; |
497 | if (ret != QDialog::Accepted) |
498 | { |
499 | return aFilename; |
500 | } |
501 | aFileNameList = aDialog->selectedFiles(); |
502 | if (!aFileNameList.isEmpty()) |
503 | { |
504 | aFilename = aFileNameList[0]; |
505 | } |
506 | |
507 | if (!QFileInfo(aFilename).completeSuffix().length()) |
508 | { |
509 | QString selFilter = aDialog->selectedNameFilter(); |
510 | int idx = selFilter.indexOf("(*."); |
511 | if (idx != -1) |
512 | { |
513 | QString tail = selFilter.mid(idx + 3); |
514 | idx = tail.indexOf(" "); |
515 | if (idx == -1) |
516 | { |
517 | idx = tail.indexOf(")"); |
518 | } |
519 | QString ext = tail.left(idx); |
520 | if (ext.length()) |
521 | { |
522 | aFilename += QString(".") + ext; |
523 | } |
524 | } |
525 | } |
526 | |
527 | return aFilename; |
528 | } |
529 | |
530 | TranslateDialog* ApplicationCommonWindow::getDataExchangeDialog(const QString& theSampleName) |
531 | { |
532 | TranslateDialog* aTranslateDialog = new TranslateDialog(this, 0, true); |
533 | TCollection_AsciiString aSampleName(theSampleName.toUtf8().data()); |
534 | |
535 | if (DataExchangeSamples::IsExportSample(aSampleName)) |
536 | { |
537 | aTranslateDialog->setWindowTitle("Export file"); |
538 | aTranslateDialog->setFileMode(QFileDialog::AnyFile); |
539 | aTranslateDialog->setAcceptMode(QFileDialog::AcceptSave); |
540 | } |
541 | else if (DataExchangeSamples::IsImportSample(aSampleName)) |
542 | { |
543 | aTranslateDialog->setWindowTitle("Import file"); |
544 | aTranslateDialog->setFileMode(QFileDialog::ExistingFile); |
545 | aTranslateDialog->setAcceptMode(QFileDialog::AcceptOpen); |
546 | } |
547 | QString aFormatFilter; |
548 | if (DataExchangeSamples::IsBrepSample(aSampleName)) |
549 | { |
550 | aFormatFilter = "BREP Files(*.brep *.rle)"; |
551 | } |
552 | else if (DataExchangeSamples::IsStepSample(aSampleName)) |
553 | { |
554 | aFormatFilter = "STEP Files (*.stp *.step)"; |
555 | aTranslateDialog->addMode(STEPControl_ManifoldSolidBrep, "Manifold Solid Brep"); |
556 | aTranslateDialog->addMode(STEPControl_FacetedBrep, "Faceted Brep"); |
557 | aTranslateDialog->addMode(STEPControl_ShellBasedSurfaceModel, "Shell Based Surface Model"); |
558 | aTranslateDialog->addMode(STEPControl_GeometricCurveSet, "Geometric Curve Set"); |
559 | } |
560 | else if (DataExchangeSamples::IsIgesSample(aSampleName)) |
561 | { |
562 | aFormatFilter = "IGES Files (*.igs *.iges)"; |
563 | } |
564 | else if (DataExchangeSamples::IsStlSample(aSampleName)) |
565 | { |
566 | aFormatFilter = "STL Files (*.stl)"; |
567 | } |
568 | else if (DataExchangeSamples::IsVrmlSample(aSampleName)) |
569 | { |
570 | aFormatFilter = "VRML Files (*.vrml)"; |
571 | } |
572 | else if (DataExchangeSamples::IsImageSample(aSampleName)) |
573 | { |
574 | aFormatFilter = "All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"; |
575 | } |
576 | QStringList aFilters; |
577 | aFilters.append(aFormatFilter); |
578 | aFilters.append("All Files(*.*)"); |
579 | |
580 | aTranslateDialog->setNameFilters(aFilters); |
581 | aTranslateDialog->clear(); |
582 | return aTranslateDialog; |
583 | } |
584 | |
585 | TranslateDialog* ApplicationCommonWindow::getOcafDialog(const QString& theSampleName) |
586 | { |
587 | TranslateDialog* aTranslateDialog = new TranslateDialog(this, 0, true); |
588 | TCollection_AsciiString aSampleName(theSampleName.toUtf8().data()); |
589 | |
590 | if (OcafSamples::IsExportSample(aSampleName)) |
591 | { |
592 | aTranslateDialog->setWindowTitle("Export file"); |
593 | aTranslateDialog->setFileMode(QFileDialog::AnyFile); |
594 | aTranslateDialog->setAcceptMode(QFileDialog::AcceptSave); |
595 | } |
596 | else if (OcafSamples::IsImportSample(aSampleName)) |
597 | { |
598 | aTranslateDialog->setWindowTitle("Import file"); |
599 | aTranslateDialog->setFileMode(QFileDialog::ExistingFile); |
600 | aTranslateDialog->setAcceptMode(QFileDialog::AcceptOpen); |
601 | } |
602 | QStringList aFilters; |
603 | if (OcafSamples::IsBinarySample(aSampleName)) |
604 | { |
605 | aFilters.append("Binary OCAF Sample (*.cbf)"); |
606 | } |
607 | if (OcafSamples::IsXmlSample(aSampleName)) |
608 | { |
609 | aFilters.append("XML OCAF Sample (*.xml)"); |
610 | } |
611 | aFilters.append("All Files(*.*)"); |
612 | |
613 | aTranslateDialog->setNameFilters(aFilters); |
614 | aTranslateDialog->clear(); |
615 | return aTranslateDialog; |
616 | } |
617 | |
8833fd4d |
618 | QMenu* ApplicationCommonWindow::MenuFromDomNode(QDomElement& theItemElement, |
619 | QWidget* theParent, |
620 | QSignalMapper* theMapper) |
a2176e65 |
621 | { |
8833fd4d |
622 | QString anItemName = theItemElement.attribute("name"); |
623 | QMenu* aMenu = new QMenu(anItemName, theParent); |
624 | QDomElement anChildItemElement = theItemElement.firstChildElement("MenuItem"); |
625 | QDomElement anSampleElement = theItemElement.firstChildElement("Sample"); |
626 | |
627 | while(anChildItemElement.isElement()) |
a2176e65 |
628 | { |
8833fd4d |
629 | aMenu->addMenu(MenuFromDomNode(anChildItemElement, aMenu, theMapper)); |
630 | anChildItemElement = anChildItemElement.nextSibling().toElement(); |
a2176e65 |
631 | } |
8833fd4d |
632 | |
633 | while(anSampleElement.isElement()) |
a2176e65 |
634 | { |
8833fd4d |
635 | QString aSampleName = anSampleElement.attribute("name"); |
636 | QString aSampleFunction = anSampleElement.attribute("function"); |
637 | QAction* anAction = aMenu->addAction(aSampleFunction); |
638 | anAction->setText(aSampleName); |
639 | theMapper->setMapping(anAction, aSampleFunction); |
640 | connect(anAction, SIGNAL(triggered()), theMapper, SLOT(map())); |
641 | anSampleElement = anSampleElement.nextSibling().toElement(); |
a2176e65 |
642 | } |
643 | return aMenu; |
644 | } |
645 | |
8833fd4d |
646 | void ApplicationCommonWindow::MenuFormXml(const QString& thePath, |
647 | QSignalMapper* theMapper, |
648 | QList<QMenu*>& theMunusList) |
a2176e65 |
649 | { |
8833fd4d |
650 | QDomDocument aDomDocument; |
a2176e65 |
651 | theMunusList.clear(); |
8833fd4d |
652 | QFile aXmlFile(thePath); |
a2176e65 |
653 | QString anErrorMessage; |
8833fd4d |
654 | if (aXmlFile.error() != QFile::NoError) |
a2176e65 |
655 | { |
8833fd4d |
656 | anErrorMessage = aXmlFile.errorString(); |
a2176e65 |
657 | Message::SendFail() << "QFile creating error: " << anErrorMessage.toUtf8().constData(); |
8833fd4d |
658 | aXmlFile.close(); |
a2176e65 |
659 | return; |
660 | } |
8833fd4d |
661 | if (!aXmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) |
a2176e65 |
662 | { |
663 | Message::SendFail() << "File " << thePath.toUtf8().constData() << " could not open"; |
8833fd4d |
664 | if (aXmlFile.error() != QFile::NoError) |
a2176e65 |
665 | { |
8833fd4d |
666 | anErrorMessage = aXmlFile.errorString(); |
a2176e65 |
667 | Message::SendFail() << "QFile opening error: " << anErrorMessage.toUtf8().constData(); |
668 | } |
8833fd4d |
669 | aXmlFile.close(); |
a2176e65 |
670 | return; |
671 | } |
8833fd4d |
672 | bool aNamespaceProcessing(false); |
673 | QString anErrorMsg; |
674 | int anErrorLine(0); |
675 | int anErrorColumn(0); |
676 | if (!aDomDocument.setContent(&aXmlFile, aNamespaceProcessing, &anErrorMsg, &anErrorLine, &anErrorColumn)) |
677 | { |
678 | Message::SendFail() << "XML file parsing error: " << anErrorMsg.toStdString() |
679 | << " at line: " << anErrorLine << " column: " << anErrorColumn; |
680 | aXmlFile.close(); |
681 | return; |
682 | } |
683 | aXmlFile.close(); |
a2176e65 |
684 | |
8833fd4d |
685 | QDomElement aRootElement = aDomDocument.documentElement(); |
686 | QDomElement anItemElement = aRootElement.firstChildElement("MenuItem"); |
687 | while(!anItemElement.isNull()) |
a2176e65 |
688 | { |
8833fd4d |
689 | theMunusList.push_back(MenuFromDomNode(anItemElement, this, theMapper)); |
690 | anItemElement = anItemElement.nextSiblingElement("MenuItem"); |
a2176e65 |
691 | } |
692 | } |