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
29 #include "GeometryGUI.h"
31 // Open CASCADE Includes
32 #include <Prs3d_Drawer.hxx>
33 #include <Prs3d_IsoAspect.hxx>
36 #include "QAD_RightFrame.h"
37 #include "QAD_Config.h"
39 #include "OCCViewer_Viewer3d.h"
40 #include "OCCViewer_ViewPort3d.h"
41 #include "VTKViewer_ViewFrame.h"
42 #include "VTKViewer_InteractorStyleSALOME.h"
44 #include "SALOME_Selection.h"
48 /* The object itself created in the static method 'GetOrCreateGEOMBase()' */
49 static GEOMContext* GeomGUI = 0;
51 typedef bool OGE(int, QAD_Desktop*);
52 typedef bool OMP(QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*);
53 typedef void BP(const Handle(SALOME_InteractiveObject)&);
54 typedef bool CP(QAD_Desktop*, QPopupMenu*, const QString&,
55 const QString&, const QString&);
57 //=======================================================================
58 // function : GeometryGUI()
59 // purpose : Constructor
60 //=======================================================================
61 GeometryGUI::GeometryGUI( const QString& theName, QObject* theParent ) :
62 SALOMEGUI( theName, theParent )
66 //=======================================================================
67 // function : ~GeometryGUI()
68 // purpose : Destructor
69 //=======================================================================
70 GeometryGUI::~GeometryGUI()
75 //=======================================================================
76 // function : GetOrCreateGEOMBase()
77 // purpose : Gets or create an object 'GEOMBase' with initialisations
78 // : Returns 'GeomGUI' as a pointer
79 //=======================================================================
80 GEOMContext* GeometryGUI::GetOrCreateGeometryGUI(QAD_Desktop* desktop)
82 GeomGUI = GeomGUI->GetOrCreateGeomGUI(desktop);
87 //=======================================================================
88 // function : OnGUIEvent() [static]
89 // purpose : manage all events on GUI
90 //=======================================================================
91 bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
93 GeometryGUI::GetOrCreateGeometryGUI(parent);
95 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
98 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
100 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
105 Mb->setItemEnabled(404, 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 == 111 || // MENU FILE - IMPORT BREP
114 theCommandID == 112 || // MENU FILE - IMPORT IGES
115 theCommandID == 113 || // MENU FILE - IMPORT STEP
116 theCommandID == 121 || // MENU FILE - EXPORT BREP
117 theCommandID == 122 || // MENU FILE - EXPORT IGES
118 theCommandID == 123 || // MENU FILE - EXPORT STEP
119 theCommandID == 31 || // MENU EDIT - COPY
120 theCommandID == 33 || // MENU EDIT - DELETE
121 theCommandID == 411 || // MENU SETTINGS - ADD IN STUDY
122 theCommandID == 412 || // MENU SETTINGS - SHADING COLOR
123 theCommandID == 413 || // MENU SETTINGS - ISOS
124 theCommandID == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
125 theCommandID == 5103 || // MENU TOOLS - CHECK GEOMETRY
126 theCommandID == 5104 || // MENU TOOLS - LOAD SCRIPT
127 theCommandID == 8032 || // POPUP VIEWER - COLOR
128 theCommandID == 8033 || // POPUP VIEWER - TRANSPARENCY
129 theCommandID == 8034 || // POPUP VIEWER - ISOS
130 theCommandID == 804 || // POPUP VIEWER - ADD IN STUDY
131 theCommandID == 901 || // OBJECT BROWSER - RENAME
132 theCommandID == 9024) { // OBJECT BROWSER - OPEN
133 if(!GeomGUI->LoadLibrary("libGEOMToolsGUI.so"))
136 else if(theCommandID == 211 || // MENU VIEW - WIREFRAME/SHADING
137 theCommandID == 212 || // MENU VIEW - DISPLAY ALL
138 theCommandID == 213 || // MENU VIEW - DISPLAY ONLY
139 theCommandID == 214 || // MENU VIEW - ERASE ALL
140 theCommandID == 215 || // MENU VIEW - ERASE ONLY
141 theCommandID == 8031) { // POPUP VIEWER - WIREFRAME/SHADING
142 if(!GeomGUI->LoadLibrary("libDisplayGUI.so"))
145 else if(theCommandID == 4011 || // MENU BASIC - POINT
146 theCommandID == 4012 || // MENU BASIC - LINE
147 theCommandID == 4013 || // MENU BASIC - CIRCLE
148 theCommandID == 4014 || // MENU BASIC - ELLIPSE
149 theCommandID == 4015 || // MENU BASIC - ARC
150 theCommandID == 4016 || // MENU BASIC - VECTOR
151 theCommandID == 4017 || // MENU BASIC - PLANE
152 theCommandID == 4018) { // MENU BASIC - WPLANE
153 if(!GeomGUI->LoadLibrary("libBasicGUI.so"))
156 else if(theCommandID == 4021 || // MENU PRIMITIVE - BOX
157 theCommandID == 4022 || // MENU PRIMITIVE - CYLINDER
158 theCommandID == 4023 || // MENU PRIMITIVE - SPHERE
159 theCommandID == 4024 || // MENU PRIMITIVE - TORUS
160 theCommandID == 4025) { // MENU PRIMITIVE - CONE
161 if(!GeomGUI->LoadLibrary("libPrimitiveGUI.so"))
164 else if(theCommandID == 4031 || // MENU GENERATION - PRISM
165 theCommandID == 4032 || // MENU GENERATION - REVOLUTION
166 theCommandID == 4033 || // MENU GENERATION - FILLING
167 theCommandID == 4034) { // MENU GENERATION - PIPE
168 if(!GeomGUI->LoadLibrary("libGenerationGUI.so"))
171 else if(theCommandID == 404 || // MENU ENTITY - SKETCHER
172 theCommandID == 407) { // MENU ENTITY - EXPLODE
173 if(!GeomGUI->LoadLibrary("libEntityGUI.so"))
176 else if(theCommandID == 4081 || // MENU BUILD - EDGE
177 theCommandID == 4082 || // MENU BUILD - WIRE
178 theCommandID == 4083 || // MENU BUILD - FACE
179 theCommandID == 4084 || // MENU BUILD - SHELL
180 theCommandID == 4085 || // MENU BUILD - SOLID
181 theCommandID == 4086) { // MENU BUILD - COMPUND
182 if(!GeomGUI->LoadLibrary("libBuildGUI.so"))
185 else if(theCommandID == 5011 || // MENU BOOLEAN - FUSE
186 theCommandID == 5012 || // MENU BOOLEAN - COMMON
187 theCommandID == 5013 || // MENU BOOLEAN - CUT
188 theCommandID == 5014) { // MENU BOOLEAN - SECTION
189 if(!GeomGUI->LoadLibrary("libBooleanGUI.so"))
192 else if(theCommandID == 5021 || // MENU TRANSFORMATION - TRANSLATION
193 theCommandID == 5022 || // MENU TRANSFORMATION - ROTATION
194 theCommandID == 5023 || // MENU TRANSFORMATION - MIRROR
195 theCommandID == 5024 || // MENU TRANSFORMATION - SCALE
196 theCommandID == 5025 || // MENU TRANSFORMATION - MULTI-TRANSLATION
197 theCommandID == 5026) { // MENU TRANSFORMATION - MULTI-ROTATION
198 if(!GeomGUI->LoadLibrary("libTransformationGUI.so"))
201 else if(theCommandID == 503 || // MENU OPERATION - PARTITION
202 theCommandID == 504 || // MENU OPERATION - ARCHIMEDE
203 theCommandID == 505 || // MENU OPERATION - FILLET
204 theCommandID == 506) { // MENU OPERATION - CHAMFER
205 if(!GeomGUI->LoadLibrary("libOperationGUI.so"))
208 else if(theCommandID == 601 || // MENU REPAIR - SEWING
209 theCommandID == 602 || // MENU REPAIR - ORIENTATION
210 theCommandID == 603 || // MENU REPAIR - SUPPRESS FACES
211 theCommandID == 604) { // MENU REPAIR - SUPPRESS HOLE
212 if(!GeomGUI->LoadLibrary("libRepairGUI.so"))
215 else if(theCommandID == 701 || // MENU MEASURE - PROPERTIES
216 theCommandID == 702 || // MENU MEASURE - CDG
217 theCommandID == 703 || // MENU MEASURE - INERTIA
218 theCommandID == 7041 || // MENU MEASURE - BOUNDING BOX
219 theCommandID == 7042 || // MENU MEASURE - MIN DISTANCE
220 theCommandID == 705 || // MENU MEASURE - TOLERANCE
221 theCommandID == 706 || // MENU MEASURE - WHATIS
222 theCommandID == 707) { // MENU MEASURE - CHECK
223 if(!GeomGUI->LoadLibrary("libMeasureGUI.so"))
229 //Load Function OnGUIEvent
230 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("OnGUIEvent");
233 f1 = (bool (*) (int, QAD_Desktop*)) osdF;
234 (*f1)(theCommandID, parent);
243 //=================================================================================
244 // function : OnKeyPress()
245 // purpose : [static]
246 //=================================================================================
247 bool GeometryGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
249 GeometryGUI::GetOrCreateGeometryGUI(parent);
251 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
258 //=================================================================================
259 // function : OnMouseMove()
260 // purpose : [static] manage mouse events
261 //=================================================================================
262 bool GeometryGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
264 GeometryGUI::GetOrCreateGeometryGUI(parent);
266 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
273 //=================================================================================
274 // function : 0nMousePress()
275 // purpose : [static] manage mouse events
276 //=================================================================================
277 bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
279 GeometryGUI::GetOrCreateGeometryGUI(parent);
281 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
284 if(GeomGUI->myState == 0) {
285 if(!GeomGUI->LoadLibrary("libBasicGUI.so"))
288 //Load Function OnMousePress
289 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("OnMousePress");
292 f1 = (bool (*) (QMouseEvent*, QAD_Desktop*, QAD_StudyFrame*)) osdF;
293 (*f1)(pe, parent, studyFrame);
300 static void UpdateVtkSelection(QAD_Desktop* parent)
302 if (!parent->getActiveStudy()) return;
304 QList<QAD_StudyFrame> aFrameList = parent->getActiveStudy()->getStudyFrames();
306 for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
307 if (aStudyFrame->getTypeView() == VIEW_VTK) {
308 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
309 VTKViewer_ViewFrame* aVtkViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
310 if (!aVtkViewFrame) continue;
311 VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
313 anInteractor->SetSelectionProp();
314 anInteractor->SetSelectionTolerance();
315 VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
317 aStyle->setPreselectionProp();
325 //=================================================================================
326 // function : SetSettings()
327 // purpose : [static]
328 //=================================================================================
329 bool GeometryGUI::SetSettings(QAD_Desktop* parent)
331 GeometryGUI::GetOrCreateGeometryGUI(parent);
332 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
333 QAD_Study* ActiveStudy = parent->getActiveStudy();
335 /* Wireframe or Shading */
337 bool ViewOCC = false;
338 if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
339 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
340 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
341 DisplayMode = ic->DisplayMode();
344 else if(ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
345 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
346 DisplayMode = myRenderInter->GetDisplayMode();
350 Mb->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
352 Mb->changeItem(211, tr("GEOM_MEN_SHADING"));
356 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
357 int Settings_AddInStudy;
358 if(!AddInStudy.isEmpty())
359 Settings_AddInStudy = AddInStudy.toInt();
361 Settings_AddInStudy = 1;
362 Mb->setItemChecked(411, Settings_AddInStudy);
366 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
368 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
372 int count = ActiveStudy->getStudyFramesCount();
373 for(int i = 0; i < count; i++) {
374 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
375 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
376 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
378 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
379 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
381 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
383 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
387 Mb->setItemEnabled(404, ViewOCC);//SKETCHER
389 Mb->setItemEnabled(603, ViewOCC);//SuppressFace
390 Mb->setItemEnabled(604, ViewOCC);//SuppressHole
392 Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings
393 Mb->setItemEnabled(414, ViewOCC);// Isos Settings
395 // PAL5356: update VTK selection
396 ::UpdateVtkSelection(parent);
402 //=================================================================================
403 // function : DefinePopup()
404 // purpose : [static]
405 //=================================================================================
406 void GeometryGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
408 GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
410 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
411 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
415 if((theParent.compare("Viewer") == 0)) {
416 if(Sel->IObjectCount() == 0)
417 theContext = "NothingSelected";
420 if(Sel->IObjectCount() == 1) {
421 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
423 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
424 if(!sobj->_is_nil()) {
425 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
426 if(strcmp(scomp->GetID(), IO->getEntry()) == 0) {
427 // component is selected
428 theObject = "Component";
438 //=================================================================================
439 // function : CustomPopup()
440 // purpose : [static]
441 //=================================================================================
442 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
443 const QString& theParent, const QString& theObject)
445 GeometryGUI::GetOrCreateGeometryGUI(parent);
447 if(!GeomGUI->LoadLibrary("libGEOMBase.so"))
450 //Load Function BuildPresentation
451 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("CustomPopup");
454 f1 = (bool (*) (QAD_Desktop*, QPopupMenu*, const QString&,
455 const QString&, const QString&)) osdF;
456 (*f1)(parent, popup, theContext, theParent, theObject);
465 //=================================================================================
466 // function : activeStudyChanged()
468 //=================================================================================
469 bool GeometryGUI::ActiveStudyChanged(QAD_Desktop* parent)
471 GeometryGUI::GetOrCreateGeometryGUI(parent);
474 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
475 bool ViewOCC = false;
476 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
479 Mb->setItemEnabled(404, ViewOCC);//SKETCHER
481 Mb->setItemEnabled(603, ViewOCC);//SuppressFace
482 Mb->setItemEnabled(604, ViewOCC);//SuppressHole
484 Mb->setItemEnabled(413, ViewOCC);// ShadingColor Settings
485 Mb->setItemEnabled(414, ViewOCC);// Isos Settings
487 GeomGUI->EmitSignalCloseAllDialogs();
491 // PAL5356: update VTK selection
492 ::UpdateVtkSelection(parent);
498 //=======================================================================
499 // function : BuildPresentation()
501 //=======================================================================
502 void GeometryGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
504 GeometryGUI::GetOrCreateGeometryGUI(QAD_Application::getDesktop());
506 if(!GeomGUI->LoadLibrary("libDisplayGUI.so"))
509 //Load Function BuildPresentation
510 OSD_Function osdF = GeomGUI->myGUILibrary.DlSymb("BuildPresentation");
513 f1 = (void (*) (const Handle(SALOME_InteractiveObject)&)) osdF;
520 void GeometryGUI::SupportedViewType(int* buffer, int bufferSize)
522 if(!buffer || !bufferSize) return;
523 buffer[0] = (int)VIEW_OCC;
524 if (--bufferSize) buffer[1] = (int)VIEW_VTK;
527 void GeometryGUI::Deactivate()
530 GeomGUI->EmitSignalCloseAllDialogs();
533 static GeometryGUI aGUI("");
536 Standard_EXPORT SALOMEGUI* GetComponentGUI() {