1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI.h"
32 // Open CASCADE Includes
33 #include <Prs3d_Drawer.hxx>
34 #include <Prs3d_IsoAspect.hxx>
37 #include "QAD_RightFrame.h"
38 #include "QAD_Config.h"
40 #include "OCCViewer_Viewer3d.h"
41 #include "OCCViewer_ViewPort3d.h"
42 #include "VTKViewer_ViewFrame.h"
44 #include "SALOME_Selection.h"
46 /* The object itself created in the static method 'GetOrCreateGEOMBase()' */
47 static GEOMContext* GeomGUI = 0;
49 typedef bool OGE(int, QAD_Desktop*);
50 typedef bool OMP(QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*);
51 typedef void BP(const Handle(SALOME_InteractiveObject)&);
52 typedef bool CP(QAD_Desktop*, QPopupMenu*, const QString&,
53 const QString&, const QString&);
55 //=======================================================================
56 // function : GeometryGUI()
57 // purpose : Constructor
58 //=======================================================================
59 GeometryGUI::GeometryGUI() :
65 //=======================================================================
66 // function : ~GeometryGUI()
67 // purpose : Destructor
68 //=======================================================================
69 GeometryGUI::~GeometryGUI()
74 //=======================================================================
75 // function : GetOrCreateGEOMBase()
76 // purpose : Gets or create an object 'GEOMBase' with initialisations
77 // : Returns 'GeomGUI' as a pointer
78 //=======================================================================
79 GEOMContext* GeometryGUI::GetOrCreateGeometryGUI(QAD_Desktop* desktop)
81 GeomGUI = GeomGUI->GetOrCreateGeomGUI(desktop);
86 //=======================================================================
87 // function : OnGUIEvent() [static]
88 // purpose : manage all events on GUI
89 //=======================================================================
90 bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
92 GeometryGUI::GetOrCreateGeometryGUI(parent);
94 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
97 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
99 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
104 Mb->setItemEnabled(404, ViewOCC);//SKETCHER
105 Mb->setItemEnabled(406, ViewOCC);//SKETCHER
107 Mb->setItemEnabled(603, ViewOCC);//SuppressFace
108 Mb->setItemEnabled(604, ViewOCC);//SuppressHole
110 Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings
111 Mb->setItemEnabled(414, ViewOCC);// Isos Settings
113 if(theCommandID == 4041 || // SKETCHER - POPUP VIEWER - SEGMENT
114 theCommandID == 4042 || // SKETCHER - POPUP VIEWER - ARC
115 theCommandID == 4043 || // SKETCHER - POPUP VIEWER - SET ANGLE
116 theCommandID == 4044 || // SKETCHER - POPUP VIEWER - SET X
117 theCommandID == 4045 || // SKETCHER - POPUP VIEWER - SET Y
118 theCommandID == 4046 || // SKETCHER - POPUP VIEWER - DELETE
119 theCommandID == 4047 || // SKETCHER - POPUP VIEWER - END
120 theCommandID == 4048 || // SKETCHER - POPUP VIEWER - CLOSE
121 theCommandID == 4051 || // SKETCHER - MENU - SET PLANE
122 theCommandID == 4052 || // SKETCHER - MENU - TANGENT
123 theCommandID == 4053 || // SKETCHER - MENU - PERPENDICULAR
124 theCommandID == 4061 || // SKETCHER - MENU - LENGTH
125 theCommandID == 4062 || // SKETCHER - MENU - ANGLE
126 theCommandID == 4063 || // SKETCHER - MENU - RADIUS
127 theCommandID == 4064 || // SKETCHER - MENU - X
128 theCommandID == 4065) { // SKETCHER - MENU - Y
129 if(!GeomGUI->LoadLibrary("libEntityGUI.so"))
133 if(GeomGUI->myState == 2) {
134 Mb->setItemEnabled(405, false);//SKETCHER
135 GeomGUI->GetSketcher().Clear();
136 GeomGUI->myState = -1;
139 if(theCommandID == 111 || // MENU FILE - IMPORT BREP
140 theCommandID == 112 || // MENU FILE - IMPORT IGES
141 theCommandID == 113 || // MENU FILE - IMPORT STEP
142 theCommandID == 121 || // MENU FILE - EXPORT BREP
143 theCommandID == 122 || // MENU FILE - EXPORT IGES
144 theCommandID == 123 || // MENU FILE - EXPORT STEP
145 theCommandID == 31 || // MENU EDIT - COPY
146 theCommandID == 33 || // MENU EDIT - DELETE
147 theCommandID == 411 || // MENU SETTINGS - ADD IN STUDY
148 theCommandID == 412 || // MENU SETTINGS - SHADING COLOR
149 theCommandID == 413 || // MENU SETTINGS - ISOS
150 theCommandID == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
151 theCommandID == 5103 || // MENU TOOLS - CHECK GEOMETRY
152 theCommandID == 5104 || // MENU TOOLS - LOAD SCRIPT
153 theCommandID == 8032 || // POPUP VIEWER - COLOR
154 theCommandID == 8033 || // POPUP VIEWER - TRANSPARENCY
155 theCommandID == 8034 || // POPUP VIEWER - ISOS
156 theCommandID == 804 || // POPUP VIEWER - ADD IN STUDY
157 theCommandID == 901 || // OBJECT BROWSER - RENAME
158 theCommandID == 9024) { // OBJECT BROWSER - OPEN
159 if(!GeomGUI->LoadLibrary("libGEOMToolsGUI.so"))
162 else if(theCommandID == 211 || // MENU VIEW - WIREFRAME/SHADING
163 theCommandID == 212 || // MENU VIEW - DISPLAY ALL
164 theCommandID == 213 || // MENU VIEW - DISPLAY ONLY
165 theCommandID == 214 || // MENU VIEW - ERASE ALL
166 theCommandID == 215 || // MENU VIEW - ERASE ONLY
167 theCommandID == 8031) { // POPUP VIEWER - WIREFRAME/SHADING
168 if(!GeomGUI->LoadLibrary("libDisplayGUI.so"))
171 else if(theCommandID == 4011 || // MENU BASIC - POINT
172 theCommandID == 4012 || // MENU BASIC - LINE
173 theCommandID == 4013 || // MENU BASIC - CIRCLE
174 theCommandID == 4014 || // MENU BASIC - ELLIPSE
175 theCommandID == 4015 || // MENU BASIC - ARC
176 theCommandID == 4016 || // MENU BASIC - VECTOR
177 theCommandID == 4017 || // MENU BASIC - PLANE
178 theCommandID == 4018) { // MENU BASIC - WPLANE
179 if(!GeomGUI->LoadLibrary("libBasicGUI.so"))
182 else if(theCommandID == 4021 || // MENU PRIMITIVE - BOX
183 theCommandID == 4022 || // MENU PRIMITIVE - CYLINDER
184 theCommandID == 4023 || // MENU PRIMITIVE - SPHERE
185 theCommandID == 4024 || // MENU PRIMITIVE - TORUS
186 theCommandID == 4025) { // MENU PRIMITIVE - CONE
187 if(!GeomGUI->LoadLibrary("libPrimitiveGUI.so"))
190 else if(theCommandID == 4031 || // MENU GENERATION - PRISM
191 theCommandID == 4032 || // MENU GENERATION - REVOLUTION
192 theCommandID == 4033 || // MENU GENERATION - FILLING
193 theCommandID == 4034) { // MENU GENERATION - PIPE
194 if(!GeomGUI->LoadLibrary("libGenerationGUI.so"))
197 else if(theCommandID == 404 || // SKETCHER
198 theCommandID == 407) { // MENU ENTITY - EXPLODE
199 if(!GeomGUI->LoadLibrary("libEntityGUI.so"))
202 else if(theCommandID == 4081 || // MENU BUILD - EDGE
203 theCommandID == 4082 || // MENU BUILD - WIRE
204 theCommandID == 4083 || // MENU BUILD - FACE
205 theCommandID == 4084 || // MENU BUILD - SHELL
206 theCommandID == 4085 || // MENU BUILD - SOLID
207 theCommandID == 4086) { // MENU BUILD - COMPUND
208 if(!GeomGUI->LoadLibrary("libBuildGUI.so"))
211 else if(theCommandID == 5011 || // MENU BOOLEAN - FUSE
212 theCommandID == 5012 || // MENU BOOLEAN - COMMON
213 theCommandID == 5013 || // MENU BOOLEAN - CUT
214 theCommandID == 5014) { // MENU BOOLEAN - SECTION
215 if(!GeomGUI->LoadLibrary("libBooleanGUI.so"))
218 else if(theCommandID == 5021 || // MENU TRANSFORMATION - TRANSLATION
219 theCommandID == 5022 || // MENU TRANSFORMATION - ROTATION
220 theCommandID == 5023 || // MENU TRANSFORMATION - MIRROR
221 theCommandID == 5024 || // MENU TRANSFORMATION - SCALE
222 theCommandID == 5025 || // MENU TRANSFORMATION - MULTI-TRANSLATION
223 theCommandID == 5026) { // MENU TRANSFORMATION - MULTI-ROTATION
224 if(!GeomGUI->LoadLibrary("libTransformationGUI.so"))
227 else if(theCommandID == 503 || // MENU OPERATION - PARTITION
228 theCommandID == 504 || // MENU OPERATION - ARCHIMEDE
229 theCommandID == 505 || // MENU OPERATION - FILLET
230 theCommandID == 506) { // MENU OPERATION - CHAMFER
231 if(!GeomGUI->LoadLibrary("libOperationGUI.so"))
234 else if(theCommandID == 601 || // MENU REPAIR - SEWING
235 theCommandID == 602 || // MENU REPAIR - ORIENTATION
236 theCommandID == 603 || // MENU REPAIR - SUPPRESS FACES
237 theCommandID == 604) { // MENU REPAIR - SUPPRESS HOLE
238 if(!GeomGUI->LoadLibrary("libRepairGUI.so"))
241 else if(theCommandID == 701 || // MENU MEASURE - PROPERTIES
242 theCommandID == 702 || // MENU MEASURE - CDG
243 theCommandID == 703 || // MENU MEASURE - INERTIA
244 theCommandID == 7041 || // MENU MEASURE - BOUNDING BOX
245 theCommandID == 7042 || // MENU MEASURE - MIN DISTANCE
246 theCommandID == 705 || // MENU MEASURE - TOLERANCE
247 theCommandID == 706 || // MENU MEASURE - WHATIS
248 theCommandID == 707) { // MENU MEASURE - CHECK
249 if(!GeomGUI->LoadLibrary("libMeasureGUI.so"))
256 //Load Function OnGUIEvent
257 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("OnGUIEvent");
260 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
261 (*f1)(theCommandID, parent);
270 //=================================================================================
271 // function : OnKeyPress()
272 // purpose : [static]
273 //=================================================================================
274 bool GeometryGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
276 GeometryGUI::GetOrCreateGeometryGUI(parent);
278 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
285 //=================================================================================
286 // function : OnMouseMove()
287 // purpose : [static] manage mouse events
288 //=================================================================================
289 bool GeometryGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
291 GeometryGUI::GetOrCreateGeometryGUI(parent);
293 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
296 if(GeomGUI->myState == 2) {
297 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort();
298 GeomGUI->GetSketcher().MakeCurrentEdge(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView());
305 //=================================================================================
306 // function : 0nMousePress()
307 // purpose : [static] manage mouse events
308 //=================================================================================
309 bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
311 GeometryGUI::GetOrCreateGeometryGUI(parent);
313 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
316 if(GeomGUI->myState == 2) {
317 GeomGUI->GetSketcher().ValidateEdge();
318 if(GeomGUI->GetSketcher().GetmyEdgesNumber() == 1) {
319 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
320 Mb->setItemEnabled(405, true); // SKETCH CONTRAINTS
323 else if(GeomGUI->myState == 0) {
324 if(!GeomGUI->LoadLibrary("libBasicGUI.so"))
327 //Load Function OnMousePress
328 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("OnMousePress");
331 f1 = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
332 (*f1)(pe, parent, studyFrame);
340 //=================================================================================
341 // function : SetSettings()
342 // purpose : [static]
343 //=================================================================================
344 bool GeometryGUI::SetSettings(QAD_Desktop* parent)
346 GeometryGUI::GetOrCreateGeometryGUI(parent);
347 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
348 QAD_Study* ActiveStudy = parent->getActiveStudy();
350 /* Wireframe or Shading */
352 bool ViewOCC = false;
353 if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
354 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
355 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
356 DisplayMode = ic->DisplayMode();
359 else if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
360 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
361 DisplayMode = myRenderInter->GetDisplayMode();
365 Mb->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
367 Mb->changeItem(211, tr("GEOM_MEN_SHADING"));
371 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
372 int Settings_AddInStudy;
373 if(!AddInStudy.isEmpty())
374 Settings_AddInStudy = AddInStudy.toInt();
376 Settings_AddInStudy = 1;
377 Mb->setItemChecked(411, Settings_AddInStudy);
381 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
383 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
387 int count = ActiveStudy->getStudyFramesCount();
388 for(int i = 0; i < count; i++) {
389 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
390 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
391 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
393 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
394 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
396 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
398 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
402 Mb->setItemEnabled(404, ViewOCC);//SKETCHER
403 Mb->setItemEnabled(405, false);//SKETCHER
404 Mb->setItemEnabled(406, ViewOCC);//SKETCHER
406 Mb->setItemEnabled(603, ViewOCC);//SuppressFace
407 Mb->setItemEnabled(604, ViewOCC);//SuppressHole
409 Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings
410 Mb->setItemEnabled(414, ViewOCC);// Isos Settings
416 //=================================================================================
417 // function : DefinePopup()
418 // purpose : [static]
419 //=================================================================================
420 void GeometryGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
422 GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
424 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
425 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
430 if((theParent.compare("Viewer") == 0)) {
431 if(GeomGUI->myState == 2)
432 theContext = "Sketch";
433 else if(Sel->IObjectCount() == 0)
434 theContext = "NothingSelected";
437 if(Sel->IObjectCount() == 1) {
438 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
440 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
441 if(!sobj->_is_nil()) {
442 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
443 if(strcmp(scomp->GetID(), IO->getEntry()) == 0) {
444 // component is selected
445 theObject = "Component";
455 //=================================================================================
456 // function : CustomPopup()
457 // purpose : [static]
458 //=================================================================================
459 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
460 const QString& theParent, const QString& theObject)
462 GeometryGUI::GetOrCreateGeometryGUI(parent);
464 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
465 if(theParent.compare("Viewer") == 0) {
466 if(theContext.compare("Sketch") == 0) {
467 SketchStatus myCS = GeomGUI->GetSketcher().GetCurrentStatus();
468 popup->setCheckable(TRUE);
469 if(myCS == SEGMENT) {
470 popup->setItemChecked(4041, true); //Sketch Segment Menu
471 popup->setItemChecked(4042, false); //Sketch Arc Menu
473 else if(myCS == ARC_CHORD) {
474 popup->setItemChecked(4041, false); //Sketch Segment Menu
475 popup->setItemChecked(4042, true); //Sketch Arc Menu
482 if(!GeomGUI->LoadLibrary("libGEOMBase.so"))
485 //Load Function BuildPresentation
486 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("CustomPopup");
489 f1 = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString&,
490 const QString&, const QString&)) osdF;
491 (*f1)(parent, popup, theContext, theParent, theObject);
500 //=================================================================================
501 // function : activeStudyChanged()
503 //=================================================================================
504 void GeometryGUI::activeStudyChanged(QAD_Desktop* parent)
506 GeometryGUI::GetOrCreateGeometryGUI(parent);
509 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
510 if(GeomGUI->myState == 2) {
511 Mb->setItemEnabled(405, false);//SKETCHER
512 GeomGUI->GetSketcher().Clear();
513 GeomGUI->myState = -1;
516 bool ViewOCC = false;
517 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
520 Mb->setItemEnabled(404, ViewOCC);//SKETCHER
521 Mb->setItemEnabled(406, ViewOCC);//SKETCHER
523 Mb->setItemEnabled(603, ViewOCC);//SuppressFace
524 Mb->setItemEnabled(604, ViewOCC);//SuppressHole
526 Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings
527 Mb->setItemEnabled(414, ViewOCC);// Isos Settings
529 GeomGUI->EmitSignalCloseAllDialogs();
536 //=======================================================================
537 // function : BuildPresentation()
539 //=======================================================================
540 void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
542 GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
544 if(!GeomGUI->LoadLibrary("libDisplayGUI.so"))
547 //Load Function BuildPresentation
548 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("BuildPresentation");
551 f1 = (void (*) (const Handle(SALOME_InteractiveObject)&)) osdF;
558 //=================================================================================
560 //=================================================================================
563 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
564 {return GeometryGUI::OnGUIEvent(theCommandID, parent);}
566 bool OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
567 {return GeometryGUI::OnKeyPress(pe, parent, studyFrame);}
569 bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
570 {return GeometryGUI::OnMousePress(pe, parent, studyFrame);}
572 bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
573 {return GeometryGUI::OnMouseMove(pe, parent, studyFrame);}
575 bool SetSettings(QAD_Desktop* parent)
576 {return GeometryGUI::SetSettings(parent);}
578 bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
579 const QString & theParent, const QString & theObject)
580 {return GeometryGUI::CustomPopup(parent, popup, theContext, theParent, theObject);}
582 void definePopup(QString & theContext, QString & parent, QString & theObject)
583 {GeometryGUI::DefinePopup(theContext, parent, theObject);}
585 bool activeStudyChanged(QAD_Desktop* parent)
586 {GeometryGUI::activeStudyChanged(parent);}
588 void buildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
589 {GeometryGUI::BuildPresentation(theIO);}
591 void supportedViewType(int* buffer, int bufferSize)
593 if(!buffer || !bufferSize) return;
594 buffer[0] = (int)VIEW_OCC;
595 if (--bufferSize) buffer[1] = (int)VIEW_VTK;