00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <QtGui/QtGui>
00027 #include <QtGui/QFileDialog>
00028 #include <QtCore/QTextStream>
00029 #include <QtCore/QFileInfo>
00030 #include <QtCore/QString>
00031
00032 #include <Aspect_RectangularGrid.hxx>
00033 #include <V3d_View.hxx>
00034
00035 #include "qoccapplication.h"
00036 #include "qoccdocument.h"
00037 #include "qoccmainwindow.h"
00038 #include "qocccommands.h"
00039
00040 void LoadBottle ( Handle(AIS_InteractiveContext) theContext );
00041 void ShowOrigin ( Handle(AIS_InteractiveContext) theContext );
00042 void AddVertex ( double x, double y, double z, Handle(AIS_InteractiveContext) theContext );
00043
00044 QoccMainWindow::QoccMainWindow()
00045 : myLastFolder(tr(""))
00046 {
00047
00048 QoccDocument* doc = qGeomApp->createDocument();
00049 myController = new QoccController( doc );
00050
00051 myTabWidget = new QTabWidget( this );
00052 myTabWidget->setObjectName( QString::fromUtf8( "myTabWidget" ) );
00053 myTabWidget->setTabShape( QTabWidget::Rounded );
00054
00055 mySketchFrame = new QoccFrame( myController, this );
00056 myTabWidget->addTab( mySketchFrame, tr( "Sketch" ) );
00057
00058 setCentralWidget( myTabWidget );
00059
00060 #if 0
00061 QAction* anAction = new QAction(tr("&Faces"), this);
00062 anAction->setStatusTip(tr("Highlight faces"));
00063 anAction->setIcon(QIcon(QString::fromUtf8(":/icons/actions/22x22/viewmagall.png")));
00064 #endif
00065
00066 createActions();
00067 createMenus();
00068 createToolBars();
00069
00070 statusBar()->showMessage(tr("A context menu is available by right-clicking"));
00071
00072 setWindowTitle(tr("QtOPENCASCADE"));
00073 setMinimumSize(160, 160);
00074
00075 #if 0
00076
00077
00078 int doc_id = myController->getDocument()->id();
00079 double radius = 50.;
00080
00081 qGeomApp->basicOps( doc_id )->StartOperation();
00082 Handle(GEOM_Object) centre = qGeomApp->basicOps( doc_id )->MakePointXYZ( 50., 50., 0.);
00083 Handle(GEOM_Object) vector = qGeomApp->basicOps( doc_id )->MakeVectorDXDYDZ( 0., 0., 100.);
00084 Handle(GEOM_Object) line = qGeomApp->basicOps( doc_id )->MakeLine(centre, vector);
00085 myController->getDocument()->RegisterPresentation(centre);
00086 myController->getDocument()->RegisterPresentation(line);
00087 qGeomApp->basicOps( doc_id )->FinishOperation();
00088
00089 qGeomApp->curvesOps( doc_id )->StartOperation();
00090 Handle(GEOM_Object) circle = qGeomApp->curvesOps( doc_id )->MakeCirclePntVecR(centre, vector, radius);
00091 myController->getDocument()->RegisterPresentation(circle);
00092 qGeomApp->curvesOps( doc_id )->FinishOperation();
00093
00094 #endif
00095
00096 #if 0
00097
00098
00099 qGeomEngine->GetI3DPrimOperations( doc->id() )->StartOperation();
00100 Handle(GEOM_Object) anObj1 = qGeomEngine->GetI3DPrimOperations( doc->id() )->MakeBoxDXDYDZ(100.,100.,200.);
00101 doc->RegisterPresentation(anObj1);
00102 qGeomEngine->GetI3DPrimOperations(1)->FinishOperation();
00103
00104
00105 qGeomEngine->GetI3DPrimOperations( doc->id() )->StartOperation();
00106 Handle(GEOM_Object) anObj2 = qGeomEngine->GetI3DPrimOperations( doc->id() )->MakeCylinderRH(50.,100.);
00107 doc->RegisterPresentation(anObj2);
00108 qGeomEngine->GetI3DPrimOperations(1)->FinishOperation();
00109
00110
00111 qGeomEngine->GetI3DPrimOperations( doc->id() )->StartOperation();
00112 Handle(GEOM_Object) anObj3 = qGeomEngine->GetIBooleanOperations( doc->id() )->MakeBoolean(anObj1,anObj2,2);
00113
00114
00115 doc->RemovePresentation(anObj1);
00116 doc->RemovePresentation(anObj2);
00117
00118
00119 doc->RegisterPresentation(anObj3);
00120 qGeomEngine->GetIBooleanOperations( doc->id() )->FinishOperation();
00121
00122
00123 qGeomEngine->GetILocalOperations( doc->id() )->StartOperation();
00124 Handle(GEOM_Object) anObj4 = qGeomEngine->GetILocalOperations( doc->id() )->MakeFilletAll(anObj3,5.);
00125
00126
00127 doc->RemovePresentation(anObj3);
00128
00129
00130 doc->RegisterPresentation(anObj4);
00131 qGeomEngine->GetILocalOperations( doc->id() )->FinishOperation();
00132
00133 #endif
00134
00135 }
00136
00137 void QoccMainWindow::fileNew()
00138 {
00139 statusBar()->showMessage(tr("Invoked File|New"));
00140 myController->clearCommand ();
00141 myController->clearAllLocalContexts();
00142 myController->deleteAllObjects();
00143 }
00144
00145 void QoccMainWindow::fileOpen()
00146 {
00147 QString fileName;
00148 QString fileType;
00149 QFileInfo fileInfo;
00150
00151 QoccInputOutput::FileFormat format;
00152 QoccInputOutput reader;
00153
00154 statusBar()->showMessage(tr("Invoked File|Open"));
00155 myController->clearCommand ();
00156
00157 fileName = QFileDialog::getOpenFileName ( this,
00158 tr("Open File"),
00159 myLastFolder,
00160 tr( "All drawing types (*.brep *.rle *.igs *iges *.stp *.step *stl);;"
00161 "BREP (*.brep *.rle);;"
00162 "STEP (*.step *.stp);;"
00163 "IGES (*.iges *.igs);;"
00164 "STL (*.stl)" ));
00165 if (!fileName.isEmpty())
00166 {
00167 fileInfo.setFile(fileName);
00168 fileType = fileInfo.suffix();
00169 if (fileType.toLower() == tr("brep") || fileType.toLower() == tr("rle"))
00170 {
00171 format = QoccInputOutput::FormatBREP;
00172 }
00173 if (fileType.toLower() == tr("step") || fileType.toLower() == tr("stp"))
00174 {
00175 format = QoccInputOutput::FormatSTEP;
00176 }
00177 if (fileType.toLower() == tr("iges") || fileType.toLower() == tr("igs"))
00178 {
00179 format = QoccInputOutput::FormatIGES;
00180 }
00181 if (fileType.toLower() == tr("stl"))
00182 {
00183 format = QoccInputOutput::FormatSTL;
00184 }
00185 myController->clearAllLocalContexts();
00186 myLastFolder = fileInfo.absolutePath();
00187 emit fileOpening();
00188 reader.importModel ( fileInfo.absoluteFilePath(), format, myController->getContext() );
00189 emit fileOpened();
00190 }
00191 }
00192
00193 void QoccMainWindow::fileSave()
00194 {
00195 statusBar()->showMessage(tr("Invoked File|Save"));
00196 myController->clearCommand ();
00197 }
00198
00199 void QoccMainWindow::filePrint()
00200 {
00201 statusBar()->showMessage(tr("Invoked File|Print"));
00202 myController->clearCommand ();
00203 }
00204
00205 void QoccMainWindow::fileClose()
00206 {
00207 statusBar()->showMessage(tr("Invoked File|Close"));
00208 myController->clearCommand ();
00209 }
00210
00211 void QoccMainWindow::undo()
00212 {
00213 statusBar()->showMessage(tr("Invoked Edit|Undo"));
00214 myController->undo();
00215 myController->clearCommand ();
00216 }
00217
00218 void QoccMainWindow::redo()
00219 {
00220 statusBar()->showMessage(tr("Invoked Edit|Redo"));
00221 myController->redo();
00222 myController->clearCommand ();
00223 }
00224
00225 void QoccMainWindow::cut()
00226 {
00227 statusBar()->showMessage(tr("Invoked Edit|Cut"));
00228 myController->clearCommand ();
00229 }
00230
00231 void QoccMainWindow::copy()
00232 {
00233 statusBar()->showMessage(tr("Invoked Edit|Copy"));
00234 myController->clearCommand ();
00235 }
00236
00237 void QoccMainWindow::paste()
00238 {
00239 statusBar()->showMessage(tr("Invoked Edit|Paste"));
00240 myController->clearCommand ();
00241 }
00242
00243 void QoccMainWindow::about()
00244 {
00245 statusBar()->showMessage(tr("Invoked Help|About"));
00246 myController->clearCommand ();
00247 QMessageBox::about(this, tr("About Menu"),
00248 tr("This Qt<b>OPENCASCADE</b> example shows "
00249 "how to create a simple Qt4 Viewer."));
00250 }
00251
00252 void QoccMainWindow::aboutQt()
00253 {
00254 statusBar()->showMessage(tr("Invoked Help|About Qt"));
00255 qApp->aboutQt();
00256 }
00257
00258 void QoccMainWindow::selectNeutralPoint()
00259 {
00260 statusBar()->showMessage(tr("Invoked Select|Clear Filters"));
00261 myController->clearAllLocalContexts();
00262 }
00263 void QoccMainWindow::selectFaces()
00264 {
00265 statusBar()->showMessage(tr("Invoked Select|Faces"));
00266 myController->setLocalContext(TopAbs_FACE);
00267 }
00268
00269 void QoccMainWindow::selectVertices()
00270 {
00271 statusBar()->showMessage(tr("Invoked Select|Vertices"));
00272 myController->setLocalContext(TopAbs_VERTEX);
00273 }
00274
00275 void QoccMainWindow::selectEdges()
00276 {
00277 statusBar()->showMessage(tr("Invoked Select|Edges"));
00278 myController->setLocalContext(TopAbs_EDGE);
00279 }
00280 void QoccMainWindow::selectWires()
00281 {
00282 statusBar()->showMessage(tr("Invoked Select|Wires"));
00283 myController->setLocalContext(TopAbs_WIRE);
00284 }
00285 void QoccMainWindow::selectShells()
00286 {
00287 statusBar()->showMessage(tr("Invoked Select|Shells"));
00288 myController->setLocalContext(TopAbs_SHELL);
00289 }
00290 void QoccMainWindow::selectSolids()
00291 {
00292 statusBar()->showMessage(tr("Invoked Select|Solids"));
00293 myController->setLocalContext(TopAbs_SOLID);
00294 }
00295 void QoccMainWindow::selectCompSolids()
00296 {
00297 statusBar()->showMessage(tr("Invoked Select|Compound Solids"));
00298 myController->setLocalContext(TopAbs_COMPSOLID);
00299 }
00300 void QoccMainWindow::selectCompounds()
00301 {
00302 statusBar()->showMessage(tr("Invoked Select|Compounds"));
00303 myController->setLocalContext(TopAbs_COMPOUND);
00304 }
00305 void QoccMainWindow::selectShapes()
00306 {
00307 statusBar()->showMessage(tr("Invoked Select|Shapes"));
00308 myController->setLocalContext(TopAbs_SHAPE);
00309 }
00310
00311 void QoccMainWindow::circleCentre()
00312 {
00313 statusBar()->showMessage(tr("Invoked Draw|Circle Centre"));
00314 QoccCommand* cc = new QoccCmdCircle2Pt( circle2PtAction );
00315 myController->setCommand ( cc );
00316 }
00317
00318 void QoccMainWindow::line2Pt()
00319 {
00320 statusBar()->showMessage(tr("Invoked Draw|Line"));
00321 QoccCommand* cc = new QoccCmdLine2Pt( line2PtAction );
00322 myController->setCommand ( cc );
00323 }
00324
00325 void QoccMainWindow::vertex()
00326 {
00327 statusBar()->showMessage(tr("Invoked Draw|Vertex"));
00328 QoccCmdPoint* cc = new QoccCmdPoint( pointAction );
00329 myController->setCommand ( cc );
00330 }
00331
00332 void QoccMainWindow::cancelDraw()
00333 {
00334 statusBar()->showMessage(tr("Cancel Draw"));
00335 myController->clearCommand ( );
00336 }
00337
00338 void QoccMainWindow::bottle()
00339 {
00340 statusBar()->showMessage(tr("Invoked File|Load Bottle"));
00341 myController->clearCommand ( );
00342 QApplication::setOverrideCursor( Qt::WaitCursor );
00343 myController->clearAllLocalContexts();
00344 myController->deleteAllObjects ();
00345
00346 LoadBottle (myController->getContext());
00347 QApplication::restoreOverrideCursor();
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 void QoccMainWindow::statusMessage (const QString aMessage)
00367 {
00368 statusBar()->showMessage(aMessage);
00369 }
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379 QAction* QoccMainWindow::createAction(const QString& caption,
00380 const QString& shortcut,
00381 const QString& tip,
00382 const char* slot,
00383 const QObject* target)
00384 {
00385 QAction* anAction = new QAction( caption, this );
00386 anAction->setShortcut( shortcut );
00387 anAction->setStatusTip( tip );
00388 connect( anAction, SIGNAL(triggered()), target == NULL ? this : target, slot );
00389 return anAction;
00390 }
00391
00392 void QoccMainWindow::createActions()
00393 {
00394 newAction = createAction( tr("&New"), tr("Ctrl+N"), tr("Create a new file"), SLOT(fileNew()) );
00395 openAction = createAction( tr("&Open..."), tr("Ctrl+O"), tr("Open an existing file"), SLOT(fileOpen()) );
00396 saveAction = createAction( tr("&Save"), tr("Ctrl+S"), tr("Save the document to disk"), SLOT(fileSave()) );
00397 printAction = createAction( tr("&Print..."),tr("Ctrl+P"), tr("Print the document"), SLOT(filePrint()) );
00398
00399 exitAction = createAction( tr("E&xit"), tr("Ctrl+X"), tr("Exit the application"), SLOT(close()) );
00400
00401 undoAction = createAction( tr("&Undo"), tr("Ctrl+Z"), tr("Undo the last operation"), SLOT(undo()) );
00402 redoAction = createAction( tr("&Redo"), tr("Ctrl+Y"), tr("Redo the last operation"), SLOT(redo()) );
00403 cutAction = createAction( tr("Cu&t"), tr("Ctrl+X"), tr("Cut to the clipboard"), SLOT(cut()) );
00404 copyAction = createAction( tr("&Copy"), tr("Ctrl+C"), tr("Copy to the clipboard"), SLOT(copy()) );
00405 pasteAction = createAction( tr("&Paste"), tr("Ctrl+V"), tr("Paste the clipboard"), SLOT(paste()) );
00406
00407 aboutAction = createAction( tr("&About"), tr(""), tr("Show the application's About box"), SLOT(about()) );
00408 aboutQtAction = createAction( tr("About &Qt"), tr(""), tr("Show the Qt library's About box"), SLOT(aboutQt()) );
00409 gridOnAction = createAction( tr("&Grid On"), tr("Ctrl+G"), tr("Turn the grid on"), SLOT(gridOn()), myController );
00410 gridOffAction = createAction( tr("Gri&d Off"), tr("Ctrl+D"), tr("Turn the grid off"), SLOT(gridOff()), myController );
00411
00412 gridXYAction = createAction( tr("XY Grid"), tr(""), tr("Grid on XY Plane"), SLOT(gridXY()), myController );
00413 gridXZAction = createAction( tr("XZ Grid"), tr(""), tr("Grid on XZ Plane"), SLOT(gridXZ()), myController );
00414 gridYZAction = createAction( tr("YZ Grid"), tr(""), tr("Grid on YZ Plane"), SLOT(gridYZ()), myController );
00415
00416 gridRectAction = createAction( tr("Rectangular"), tr(""), tr("Retangular grid"), SLOT(gridRect()), myController );
00417 gridCircAction = createAction( tr("Circular"), tr(""), tr("Circular grid"), SLOT(gridCirc()), myController );
00418
00419
00420 pointAction = new QAction(tr("&Points"), this);
00421 pointAction->setStatusTip(tr("Points"));
00422 pointAction->setIcon(QIcon(QString::fromUtf8(":/icons/icons/point.png")));
00423 connect( pointAction, SIGNAL( triggered() ), this, SLOT( vertex()) );
00424
00425 circle2PtAction = new QAction(tr("&Circle Centre, Radius"), this);
00426 circle2PtAction->setStatusTip(tr("Circle - centre, radius"));
00427 circle2PtAction->setIcon(QIcon(QString::fromUtf8(":/icons/icons/circlecentre.png")));
00428 connect( circle2PtAction, SIGNAL( triggered() ), this, SLOT( circleCentre()) );
00429
00430 line2PtAction = new QAction(tr("&Line"), this);
00431 line2PtAction->setStatusTip(tr("Line - 2 point"));
00432 line2PtAction->setIcon(QIcon(QString::fromUtf8(":/icons/icons/line.png")));
00433 connect( line2PtAction, SIGNAL( triggered() ), this, SLOT( line2Pt()) );
00434
00435 cancelDrawAction = new QAction(tr("Cancel"), this);
00436 circle2PtAction->setStatusTip(tr("Cancel"));
00437
00438 connect( cancelDrawAction, SIGNAL( triggered() ), this, SLOT( cancelDraw()) );
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448 selectVertexAction = createAction(tr("&Vertices"), "", tr("Select Vertices"), SLOT(selectVertices()));
00449 selectEdgeAction = createAction(tr("&Edges"), "", tr("Select Edges"), SLOT(selectEdges()));
00450 selectWireAction = createAction(tr("&Wires"), "", tr("Select Wires"), SLOT(selectWires()));
00451 selectFaceAction = createAction(tr("&Faces"), "", tr("Select Faces"), SLOT(selectFaces()));
00452 selectShellAction = createAction(tr("&Shells"), "", tr("Select Shells"), SLOT(selectShells()));
00453 selectNeutralAction = createAction(tr("&Normal"), "", tr("No selection filter"), SLOT(selectNeutralPoint()));
00454
00455
00456
00457 bottleAction = new QAction(tr("Load &Bottle"), this);
00458 bottleAction->setShortcut(tr("Ctrl+B"));
00459 bottleAction->setStatusTip(tr("Bottle sample."));
00460 connect(bottleAction, SIGNAL(triggered()), this, SLOT(bottle()));
00461
00462 }
00463
00464 void QoccMainWindow::createMenus()
00465 {
00466 fileMenu = menuBar()->addMenu( tr("&File") );
00467 fileMenu->addAction( newAction );
00468 fileMenu->addAction( openAction );
00469 fileMenu->addAction( saveAction );
00470 fileMenu->addAction( printAction );
00471
00472
00473
00474
00475
00476 fileMenu->addSeparator();
00477 fileMenu->addAction( bottleAction );
00478
00479 fileMenu->addSeparator();
00480 fileMenu->addAction( exitAction );
00481
00482 editMenu = menuBar()->addMenu( tr("&Edit") );
00483 editMenu->addAction( undoAction );
00484 editMenu->addAction( redoAction );
00485 editMenu->addSeparator();
00486 editMenu->addAction( cutAction );
00487 editMenu->addAction( copyAction );
00488 editMenu->addAction( pasteAction );
00489
00490 drawMenu = menuBar()->addMenu( tr("&Draw") );
00491 drawMenu->addAction( pointAction );
00492 drawMenu->addAction( line2PtAction );
00493 drawMenu->addAction( circle2PtAction );
00494 drawMenu->addSeparator();
00495 drawMenu->addAction( cancelDrawAction );
00496
00497 selectMenu = menuBar()->addMenu( tr("&Select") );
00498 selectMenu->addAction( selectVertexAction );
00499 selectMenu->addAction( selectEdgeAction );
00500 selectMenu->addAction( selectWireAction );
00501 selectMenu->addAction( selectFaceAction );
00502 selectMenu->addAction( selectShellAction );
00503 selectMenu->addSeparator();
00504 selectMenu->addAction( selectNeutralAction );
00505
00506 viewMenu = menuBar()->addMenu( tr("&View") );
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 gridMenu = viewMenu->addMenu( tr("&Grid") );
00533 gridMenu->addAction( gridOnAction );
00534 gridMenu->addAction( gridOffAction );
00535 gridMenu->addSeparator();
00536 gridMenu->addAction( gridXYAction );
00537 gridMenu->addAction( gridXZAction );
00538 gridMenu->addAction( gridYZAction );
00539 gridMenu->addSeparator();
00540 gridMenu->addAction( gridRectAction );
00541 gridMenu->addAction( gridCircAction );
00542
00543 helpMenu = menuBar()->addMenu(tr("&Help"));
00544 helpMenu->addAction(aboutAction);
00545 helpMenu->addAction(aboutQtAction);
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630 void QoccMainWindow::createToolBars()
00631 {
00632 drawToolBar = new QToolBar (tr("Drawing tools"), this);
00633 this->addToolBar(Qt::LeftToolBarArea, drawToolBar);
00634 drawToolBar->setObjectName(QString::fromUtf8("drawToolBar"));
00635 drawToolBar->setCursor(QCursor(Qt::PointingHandCursor));
00636 drawToolBar->setOrientation(Qt::Vertical);
00637
00638 drawToolBar->addAction( pointAction );
00639 drawToolBar->addAction( line2PtAction );
00640 drawToolBar->addAction( circle2PtAction );
00641 }
00642
00643
00644
00645