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"
32 #include "Utils_ORB_INIT.hxx"
33 #include "Utils_SINGLETON.hxx"
35 #include "QAD_Desktop.h"
36 #include "QAD_Application.h"
37 #include "QAD_RightFrame.h"
38 #include "QAD_Config.h"
39 #include "QAD_Tools.h"
40 #include "QAD_MessageBox.h"
41 #include "QAD_Resource.h"
42 #include "SALOMEGUI_Desktop.h"
44 #include "OCCViewer_Viewer3d.h"
45 #include "OCCViewer_ViewFrame.h"
46 #include "OCCViewer_ViewPort3d.h"
47 #include "OCCViewer_Prs.h"
49 #include "VTKViewer_ViewFrame.h"
50 #include "VTKViewer_RenderWindowInteractor.h"
51 #include "VTKViewer_InteractorStyleSALOME.h"
52 #include "VTKViewer_Prs.h"
53 #include "SALOME_Actor.h"
55 #include "SALOME_Selection.h"
56 #include "SALOME_ListIteratorOfListIO.hxx"
57 #include "GEOM_AISShape.hxx"
58 #include "GEOM_Displayer.h"
60 #include "GEOMImpl_Types.hxx"
63 #include <qfileinfo.h>
64 #include <Prs3d_Drawer.hxx>
65 #include <Prs3d_IsoAspect.hxx>
66 #include <OSD_SharedLibrary.hxx>
68 #include "utilities.h"
70 #include <vtkCamera.h>
71 #include <vtkRenderer.h>
76 Standard_EXPORT SALOMEGUI* GetComponentGUI() {
77 return GeometryGUI::GetGeomGUI();
81 //=================================================================================
83 // purpose : Set Font to a text.
84 //=================================================================================
85 class CustomItem : public QCustomMenuItem
88 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
91 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
94 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
95 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
97 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
103 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
106 bool fullSpan() const
116 //=======================================================================
117 // function : GeometryGUI::GetGeomGUI()
118 // purpose : Gets the only object of GeometryGUI [ static ]
119 //=======================================================================
120 GeometryGUI* GeometryGUI::GetGeomGUI()
122 static GeometryGUI myContext;
126 //=======================================================================
128 // purpose : Returns a reference to ORB [ static ]
129 //=======================================================================
130 CORBA::ORB_var GeometryGUI::GetORB()
132 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
136 //=======================================================================
137 // function : GeometryGUI::GeometryGUI()
138 // purpose : Constructor
139 //=======================================================================
140 GeometryGUI::GeometryGUI() :
143 QAD_Desktop* desktop = QAD_Application::getDesktop();
144 Engines::Component_var comp = desktop->getEngine( "FactoryServer", "GEOM" );
146 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
148 myActiveDialogBox = 0;
151 gp_Pnt origin = gp_Pnt(0., 0., 0.);
152 gp_Dir direction = gp_Dir(0., 0., 1.);
153 myWorkingPlane = gp_Ax3(origin, direction);
156 //=======================================================================
157 // function : GeometryGUI::~GeometryGUI()
158 // purpose : Destructor
159 //=======================================================================
160 GeometryGUI::~GeometryGUI()
164 //=======================================================================
165 // function : GeometryGUI::getLibrary()
166 // purpose : get or load GUI library by name [ internal ]
167 //=======================================================================
168 typedef GEOMGUI* (*LibraryGUI)();
169 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
171 if ( !myGUIMap.contains( libraryName ) ) {
172 // try to load library if it is not loaded yet
174 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
175 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
176 for( int i = dirList.count()-1; i >= 0; i-- ) {
177 QString dir = dirList[ i ];
178 QFileInfo fi( QAD_Tools::addSlash( dirList[ i ] ) + libraryName );
180 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
181 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
183 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
184 continue; // continue search further
186 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
187 if ( osdF != NULL ) {
188 LibraryGUI func = (GEOMGUI* (*) ())osdF;
189 GEOMGUI* libGUI = (*func)();
191 myGUIMap[ libraryName ] = libGUI;
192 break; // found and loaded!
199 if ( myGUIMap.contains( libraryName ) )
200 // library is successfully loaded
201 return myGUIMap[ libraryName ];
205 //=======================================================================
206 // function : GeometryGUI::ActiveWorkingPlane()
207 // purpose : Activate Working Plane View
208 //=======================================================================
209 void GeometryGUI::ActiveWorkingPlane()
211 gp_Dir DZ = myWorkingPlane.Direction();
212 gp_Dir DY = myWorkingPlane.YDirection();
214 if( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
215 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
216 Handle(V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
218 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
219 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
221 ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewFitAll();
223 else if( QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
224 vtkRenderer* myRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
226 vtkCamera* camera = myRenderer->GetActiveCamera();
227 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
228 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
229 camera->SetFocalPoint(0,0,0);
231 ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->onViewFitAll();
236 //=======================================================================
237 // function : GeometryGUI::SetActiveDialogBox()
238 // purpose : Set active dialog box
239 //=======================================================================
240 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
242 myActiveDialogBox = (QDialog*)aDlg;
245 //=======================================================================
246 // function : GeometryGUI::EmitSignalDeactivateDialog()
247 // purpose : Emit a signal to deactivate the active dialog Box
248 //=======================================================================
249 void GeometryGUI::EmitSignalDeactivateDialog()
251 emit SignalDeactivateActiveDialog();
254 //=======================================================================
255 // function : GeometryGUI::EmitSignalCloseAllDialogs()
256 // purpose : Emit a signal to close all non modal dialogs box
257 //=======================================================================
258 void GeometryGUI::EmitSignalCloseAllDialogs()
260 emit SignalCloseAllDialogs();
263 //=======================================================================
264 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
265 // purpose : Emit a signal to inform that default real spin box step has
267 //=======================================================================
268 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
270 emit SignalDefaultStepValueChanged(newVal);
273 //=======================================================================
274 // function : GeometryGUI::OnGUIEvent()
275 // purpose : manage all events on GUI [static]
276 //=======================================================================
277 bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
279 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
282 QMenuBar* Mb = parent->getMainMenuBar();
283 // check if current viewframe is of OCC type
284 bool ViewOCC = parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC;
285 // if current viewframe is not of OCC and not of VTK type - return immediately
286 if( !ViewOCC && parent->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
289 // disable non-OCC viewframe menu commands
290 //Mb->setItemEnabled( 404, ViewOCC ); // SKETCHER
291 Mb->setItemEnabled( 603, ViewOCC ); // SuppressFace
292 Mb->setItemEnabled( 604, ViewOCC ); // SuppressHole
293 Mb->setItemEnabled( 606, ViewOCC ); // CloseContour
294 Mb->setItemEnabled( 607, ViewOCC ); // RemoveInternalWires
295 Mb->setItemEnabled( 608, ViewOCC ); // AddPointOnEdge
296 //Mb->setItemEnabled( 609, ViewOCC ); // Free boundaries
297 Mb->setItemEnabled( 413, ViewOCC ); // Isos Settings
299 Mb->setItemEnabled( 800, ViewOCC ); // Create Group
300 Mb->setItemEnabled( 801, ViewOCC ); // Edit Group
302 Mb->setItemEnabled(9998, ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
304 GEOMGUI* library = 0;
305 // try to get-or-load corresponding GUI library
306 if( theCommandID == 111 || // MENU FILE - IMPORT BREP
307 theCommandID == 112 || // MENU FILE - IMPORT IGES
308 theCommandID == 113 || // MENU FILE - IMPORT STEP
309 theCommandID == 121 || // MENU FILE - EXPORT BREP
310 theCommandID == 122 || // MENU FILE - EXPORT IGES
311 theCommandID == 123 || // MENU FILE - EXPORT STEP
312 theCommandID == 31 || // MENU EDIT - COPY
313 theCommandID == 33 || // MENU EDIT - DELETE
314 theCommandID == 411 || // MENU SETTINGS - ADD IN STUDY
315 theCommandID == 412 || // MENU SETTINGS - SHADING COLOR
316 theCommandID == 413 || // MENU SETTINGS - ISOS
317 theCommandID == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
318 theCommandID == 5103 || // MENU TOOLS - CHECK GEOMETRY
319 theCommandID == 5104 || // MENU TOOLS - LOAD SCRIPT
320 theCommandID == 8032 || // POPUP VIEWER - COLOR
321 theCommandID == 8033 || // POPUP VIEWER - TRANSPARENCY
322 theCommandID == 8034 || // POPUP VIEWER - ISOS
323 theCommandID == 804 || // POPUP VIEWER - ADD IN STUDY
324 theCommandID == 901 || // OBJECT BROWSER - RENAME
325 theCommandID == 9024 ) { // OBJECT BROWSER - OPEN
326 library = geomGUI->getLibrary( "libGEOMToolsGUI.so" );
328 else if( theCommandID == 211 || // MENU VIEW - WIREFRAME/SHADING
329 theCommandID == 212 || // MENU VIEW - DISPLAY ALL
330 theCommandID == 213 || // MENU VIEW - DISPLAY ONLY
331 theCommandID == 214 || // MENU VIEW - ERASE ALL
332 theCommandID == 215 || // MENU VIEW - ERASE
333 theCommandID == 216 || // MENU VIEW - DISPLAY
334 theCommandID == 80311 || // POPUP VIEWER - WIREFRAME
335 theCommandID == 80312 ) { // POPUP VIEWER - SHADING
336 library = geomGUI->getLibrary( "libDisplayGUI.so" );
338 else if( theCommandID == 4011 || // MENU BASIC - POINT
339 theCommandID == 4012 || // MENU BASIC - LINE
340 theCommandID == 4013 || // MENU BASIC - CIRCLE
341 theCommandID == 4014 || // MENU BASIC - ELLIPSE
342 theCommandID == 4015 || // MENU BASIC - ARC
343 theCommandID == 4016 || // MENU BASIC - VECTOR
344 theCommandID == 4017 || // MENU BASIC - PLANE
345 theCommandID == 4018 || // MENU BASIC - WPLANE
346 theCommandID == 4019 || // MENU BASIC - CURVE
347 theCommandID == 4020 ) { // MENU BASIC - REPAIR
348 library = geomGUI->getLibrary( "libBasicGUI.so" );
350 else if( theCommandID == 4021 || // MENU PRIMITIVE - BOX
351 theCommandID == 4022 || // MENU PRIMITIVE - CYLINDER
352 theCommandID == 4023 || // MENU PRIMITIVE - SPHERE
353 theCommandID == 4024 || // MENU PRIMITIVE - TORUS
354 theCommandID == 4025 ) { // MENU PRIMITIVE - CONE
355 library = geomGUI->getLibrary( "libPrimitiveGUI.so" );
357 else if( theCommandID == 4031 || // MENU GENERATION - PRISM
358 theCommandID == 4032 || // MENU GENERATION - REVOLUTION
359 theCommandID == 4033 || // MENU GENERATION - FILLING
360 theCommandID == 4034 ) { // MENU GENERATION - PIPE
361 library = geomGUI->getLibrary( "libGenerationGUI.so" );
363 else if( theCommandID == 404 || // MENU ENTITY - SKETCHER
364 theCommandID == 407 ) { // MENU ENTITY - EXPLODE
365 library = geomGUI->getLibrary( "libEntityGUI.so" );
367 else if( theCommandID == 4081 || // MENU BUILD - EDGE
368 theCommandID == 4082 || // MENU BUILD - WIRE
369 theCommandID == 4083 || // MENU BUILD - FACE
370 theCommandID == 4084 || // MENU BUILD - SHELL
371 theCommandID == 4085 || // MENU BUILD - SOLID
372 theCommandID == 4086 ) { // MENU BUILD - COMPUND
373 library = geomGUI->getLibrary( "libBuildGUI.so" );
375 else if( theCommandID == 5011 || // MENU BOOLEAN - FUSE
376 theCommandID == 5012 || // MENU BOOLEAN - COMMON
377 theCommandID == 5013 || // MENU BOOLEAN - CUT
378 theCommandID == 5014 ) { // MENU BOOLEAN - SECTION
379 library = geomGUI->getLibrary( "libBooleanGUI.so" );
381 else if( theCommandID == 5021 || // MENU TRANSFORMATION - TRANSLATION
382 theCommandID == 5022 || // MENU TRANSFORMATION - ROTATION
383 theCommandID == 5023 || // MENU TRANSFORMATION - LOCATION
384 theCommandID == 5024 || // MENU TRANSFORMATION - MIRROR
385 theCommandID == 5025 || // MENU TRANSFORMATION - SCALE
386 theCommandID == 5026 || // MENU TRANSFORMATION - OFFSET
387 theCommandID == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
388 theCommandID == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
389 library = geomGUI->getLibrary( "libTransformationGUI.so" );
391 else if( theCommandID == 503 || // MENU OPERATION - PARTITION
392 theCommandID == 504 || // MENU OPERATION - ARCHIMEDE
393 theCommandID == 505 || // MENU OPERATION - FILLET
394 theCommandID == 506 || // MENU OPERATION - CHAMFER
395 theCommandID == 507 ) { // MENU OPERATION - CLIPPING RANGE
396 library = geomGUI->getLibrary( "libOperationGUI.so" );
398 else if( theCommandID == 601 || // MENU REPAIR - SEWING
399 theCommandID == 603 || // MENU REPAIR - SUPPRESS FACES
400 theCommandID == 604 || // MENU REPAIR - SUPPRESS HOLE
401 theCommandID == 605 || // MENU REPAIR - SHAPE PROCESSING
402 theCommandID == 606 || // MENU REPAIR - CLOSE CONTOUR
403 theCommandID == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
404 theCommandID == 608 || // MENU REPAIR - ADD POINT ON EDGE
405 theCommandID == 609 || // MENU REPAIR - FREE BOUNDARIES
406 theCommandID == 610 || // MENU REPAIR - FREE FACES
407 theCommandID == 602 ) { // MENU REPAIR - GLUE FACES
408 library = geomGUI->getLibrary( "libRepairGUI.so" );
410 else if( theCommandID == 701 || // MENU MEASURE - PROPERTIES
411 theCommandID == 702 || // MENU MEASURE - CDG
412 theCommandID == 703 || // MENU MEASURE - INERTIA
413 theCommandID == 7041 || // MENU MEASURE - BOUNDING BOX
414 theCommandID == 7042 || // MENU MEASURE - MIN DISTANCE
415 theCommandID == 705 || // MENU MEASURE - TOLERANCE
416 theCommandID == 706 || // MENU MEASURE - WHATIS
417 theCommandID == 707 || // MENU MEASURE - CHECK
418 theCommandID == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
419 theCommandID == 708 ) { // MENU MEASURE - POINT COORDINATES
420 library = geomGUI->getLibrary( "libMeasureGUI.so" );
422 else if( theCommandID == 800 || // MENU GROUP - CREATE
423 theCommandID == 801 ) { // MENU GROUP - EDIT
424 library = geomGUI->getLibrary( "libGroupGUI.so" );
426 else if( theCommandID == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
427 theCommandID == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
428 theCommandID == 9997 || // MENU BLOCKS - QUADRANGLE FACE
429 theCommandID == 99991 || // MENU BLOCKS - PROPAGATE
430 theCommandID == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
431 library = geomGUI->getLibrary( "libBlocksGUI.so" );
434 // call method of corresponding GUI library
436 return library->OnGUIEvent( theCommandID, parent );
439 QAD_MessageBox::error1( parent, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
445 //=================================================================================
446 // function : GeometryGUI::OnKeyPress()
447 // purpose : Called when any key is pressed by user [static]
448 //=================================================================================
449 bool GeometryGUI::OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
451 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
454 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
455 bOk = bOk && it.data()->OnKeyPress( pe, parent, studyFrame );
460 //=================================================================================
461 // function : GeometryGUI::OnMouseMove()
462 // purpose : Manages mouse move events [static]
463 //=================================================================================
464 bool GeometryGUI::OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
466 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
469 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
470 bOk = bOk && it.data()->OnMouseMove( pe, parent, studyFrame );
475 //=================================================================================
476 // function : GeometryGUI::0nMousePress()
477 // purpose : Manage mouse press events [static]
478 //=================================================================================
479 bool GeometryGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
481 GeometryGUI* geomGUI = GeometryGUI::GetGeomGUI();
483 // OnMousePress() should return false if this event should be processed further
484 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
485 bool processed = false;
486 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
487 processed = processed || it.data()->OnMousePress( pe, parent, studyFrame );
491 static void UpdateVtkSelection(QAD_Desktop* parent)
493 if (!parent->getActiveStudy()) return;
495 QList<QAD_StudyFrame> aFrameList = parent->getActiveStudy()->getStudyFrames();
497 for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
498 if (aStudyFrame->getTypeView() == VIEW_VTK) {
499 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
500 VTKViewer_ViewFrame* aVtkViewFrame = dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
501 if (!aVtkViewFrame) continue;
502 VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
504 anInteractor->SetSelectionProp();
505 anInteractor->SetSelectionTolerance();
506 VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
508 aStyle->setPreselectionProp();
515 //=================================================================================
516 // function : GeometryGUI::SetSettings()
517 // purpose : Called when GEOM module is activated [static]
518 //=================================================================================
519 bool GeometryGUI::SetSettings(QAD_Desktop* parent)
521 GeometryGUI* geomGUI = GetGeomGUI();
522 QMenuBar* Mb = parent->getMainMenuBar();
523 QAD_Study* ActiveStudy = parent->getActiveStudy();
527 /* Wireframe or Shading */
529 bool ViewOCC = false;
530 if ( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
531 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
532 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
533 DisplayMode = ic->DisplayMode();
536 else if (ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
537 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
538 DisplayMode = myRenderInter->GetDisplayMode();
541 if( DisplayMode == 1 )
542 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
544 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
547 /* Add in Study - !!!ALWAYS TRUE!!! */ /////// VSR : TO BE REMOVED
548 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
549 int Settings_AddInStudy;
550 /*if(!AddInStudy.isEmpty())
551 Settings_AddInStudy = AddInStudy.toInt();
554 Settings_AddInStudy = 1;
555 Mb->setItemChecked(411, Settings_AddInStudy);
558 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
560 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
563 int count = ActiveStudy->getStudyFramesCount();
564 for(int i = 0; i < count; i++) {
565 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
566 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
567 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
569 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
570 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
572 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
574 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
578 //Mb->setItemEnabled(404, ViewOCC); // SKETCHER
579 Mb->setItemEnabled(603, ViewOCC); // SuppressFace
580 Mb->setItemEnabled(604, ViewOCC); // SuppressHole
581 Mb->setItemEnabled(606, ViewOCC); // CloseContour
582 Mb->setItemEnabled(607, ViewOCC); // RemoveInternalWires
583 Mb->setItemEnabled(608, ViewOCC); // AddPointOnEdge
584 // Mb->setItemEnabled(609, ViewOCC); // Free boundaries
585 Mb->setItemEnabled(413, ViewOCC); // Isos Settings
587 Mb->setItemEnabled( 800, ViewOCC ); // Create Group
588 Mb->setItemEnabled( 801, ViewOCC ); // Edit Group
590 Mb->setItemEnabled(9998, ViewOCC); // MENU BLOCKS - MULTI-TRANSFORMATION
593 // PAL5356: update VTK selection
594 ::UpdateVtkSelection(parent);
597 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
598 bOk = bOk && it.data()->SetSettings( parent );
600 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
601 if (getenv( "GEOM_CLIPPING" ) == NULL)
603 QMenuItem* mi = Mb->findItem(50);
604 if (mi && mi->popup())
605 mi->popup()->removeItem(507);
611 //=======================================================================
612 // function : GeometryGUI::Deactivate()
613 // purpose : Called when GEOM module is deactivated [ static ]
614 //=======================================================================
615 void GeometryGUI::Deactivate()
617 GeometryGUI* geomGUI = GetGeomGUI();
618 GetGeomGUI()->EmitSignalCloseAllDialogs();
620 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
621 it.data()->Deactivate();
624 //=================================================================================
625 // function : GeometryGUI::DefinePopup()
626 // purpose : Called from desktop to define popup menu [static]
627 //=================================================================================
628 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
630 GeometryGUI* geomGUI = GetGeomGUI();
631 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
632 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
637 if ( theParent == "Viewer" ) {
638 if ( Sel->IObjectCount() == 0 )
639 theContext = "NothingSelected";
642 if ( Sel->IObjectCount() == 1 ) {
643 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
644 if( IO->hasEntry() ) {
645 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
646 if ( !sobj->_is_nil() ) {
647 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
648 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
649 // component is selected
650 theObject = "Component";
653 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
654 if ( !CORBA::is_nil( aGObj ) ) {
655 switch( aGObj->GetType() ) {
670 //=================================================================================
671 // function : GeometryGUI::CustomPopup()
672 // purpose : Called from desktop to create popup menu [static]
673 //=================================================================================
674 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
675 const QString& theParent, const QString& theObject)
677 GeometryGUI* geomGUI = GetGeomGUI();
679 // Deactivate any non modal dialog box to get the neutral point
680 geomGUI->EmitSignalDeactivateDialog();
681 QAD_Study* anActiveStudy = parent->getActiveStudy();
682 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
683 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
684 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
685 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
686 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
687 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
688 int aDisplayMode = 0;
691 if ( aViewFrame->getTypeView() == VIEW_OCC )
692 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
693 else if ( aViewFrame->getTypeView() == VIEW_VTK )
694 aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
696 int nbSel = Sel->IObjectCount();
699 ////// NOTHING SELECTED
702 else if ( nbSel == 1 ) {
703 ////// SINGLE OBJECT SELECTION
704 if ( parentComponent != parent->getActiveComponent() ) {
705 ////// selected object does not belong to GEOM module:
706 // remove all commands except Display/Erase...
708 int id = popup->idAt( 0 );
709 if ( id <= QAD_TopLabel_Popup_ID )
710 popup->removeItemAt( 0 );
716 ////// selected object belong to the GEOM module
717 // get interactive object
718 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
719 objectName = IObject->getName();
720 // if object has entry get SObject
721 SALOMEDS::SObject_var SO;
722 if ( IObject->hasEntry() )
723 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
725 if ( theObject == "Component" ) {
726 ////// menu for component
727 popup->removeItem( QAD_DisplayOnly_Popup_ID );
728 if ( !isOCCViewer && !isVTKViewer ) {
729 popup->removeItem( QAD_Display_Popup_ID );
730 popup->removeItem( QAD_Erase_Popup_ID );
734 ////// not component (should be shape)
735 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
736 popup->removeItem( 804 ); // "Add in Study"
738 // Here could be analysis of the geom shape's type
741 SALOMEDS::GenericAttribute_var aTmpAttr;
742 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
743 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
745 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
746 if ( theObject == "Shape" )
747 popup->removeItem( 800 ); // Create Group
748 else if ( theObject == "Group" )
749 popup->removeItem( 801 ); // Edit Group
752 if ( isOCCViewer || isVTKViewer ) {
753 ////// current viewer is OCC or VTK
754 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
755 if ( aViewFrame->isVisible( IObject ) ) {
756 ////// object is already displayed in the viewer
757 popup->removeItem( QAD_Display_Popup_ID );
759 ////// OCC viewer only
760 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
761 if ( occPrs && !occPrs->IsNull() ) {
762 AIS_ListOfInteractive ioList;
763 occPrs->GetObjects( ioList );
764 QMenuItem* mi = popup->findItem( 803 );
765 if ( mi && mi->popup() ) {
766 if ( ioList.First()->DisplayMode() == 0 )
767 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
768 else if ( ioList.First()->DisplayMode() == 1 )
769 mi->popup()->setItemChecked( 80312, true ); // "Shading"
770 else if ( ioList.First()->DisplayMode() < 0 )
771 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
776 ////// VTK viewer only
777 popup->removeItem( 8034 ); // "Isos"
778 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
779 if ( vtkPrs && !vtkPrs->IsNull() ) {
780 vtkActorCollection* actorList = vtkPrs->GetObjects();
781 actorList->InitTraversal();
782 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
783 QMenuItem* mi = popup->findItem( 803 );
784 if ( ac && mi && mi->popup() ) {
785 if ( ac->getDisplayMode() == 0 )
786 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
787 else if ( ac->getDisplayMode() == 1 )
788 mi->popup()->setItemChecked( 80312, true ); // "Shading"
790 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
796 ////// object is not yet displayed in the viewer
797 popup->removeItem( 803 ); // "Display Mode"
798 popup->removeItem( 8032 ); // "Color"
799 popup->removeItem( 8033 ); // "Transparency"
800 popup->removeItem( 8034 ); // "Isos"
801 popup->removeItem( QAD_Erase_Popup_ID );
806 ////// other viewer type (neither OCC nor VTK)
807 popup->removeItem( 803 ); // "Display Mode"
808 popup->removeItem( 8032 ); // "Color"
809 popup->removeItem( 8033 ); // "Transparency"
810 popup->removeItem( 8034 ); // "Isos"
811 popup->removeItem( QAD_Display_Popup_ID );
812 popup->removeItem( QAD_DisplayOnly_Popup_ID );
813 popup->removeItem( QAD_Erase_Popup_ID );
819 ////// MULTIPLE SELECTION
820 if ( parentComponent != parent->getActiveComponent() ) {
821 ////// not GEOM module objects or objects belong to different modules
822 // remove all commands except Display/Erase...
824 int id = popup->idAt( 0 );
825 if ( id <= QAD_TopLabel_Popup_ID )
826 popup->removeItemAt( 0 );
830 if ( parentComponent.isNull() ) {
831 ////// objects belong to different modules
832 popup->removeItem(QAD_Display_Popup_ID);
833 popup->removeItem(QAD_DisplayOnly_Popup_ID);
834 popup->removeItem(QAD_Erase_Popup_ID);
837 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
841 ////// all selected objects belong to GEOM module
842 popup->removeItem( 901 ); // "Rename"
844 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
845 bool isComponent = false;
846 bool needOpen = false;
847 bool needDisplay = false;
848 bool needErase = false;
849 int needToPublish = 0;
851 for( ;It.More();It.Next() ) {
852 Handle(SALOME_InteractiveObject) anIObject = It.Value();
854 if ( aViewFrame->isVisible( anIObject ) )
859 if( anIObject->hasEntry() ) {
860 needToPublish = -1; /////// VSR : TO BE REMOVED
861 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
862 SALOMEDS::GenericAttribute_var aTmpAttr;
863 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
864 needOpen = true; /////// VSR : TO BE REMOVED
865 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
869 if ( needToPublish != -1 ) needToPublish = 1;
872 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
873 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
874 popup->removeItem( 803 ); // "Display Mode"
875 popup->removeItem( 8032 ); // "Color"
876 popup->removeItem( 8033 ); // "Transparency"
877 popup->removeItem( 8034 ); // "Isos"
878 popup->removeItem( 804 ); // "Add in Study"
879 popup->removeItem( QAD_DisplayOnly_Popup_ID );
880 popup->removeItem( QAD_Display_Popup_ID );
881 popup->removeItem( QAD_Erase_Popup_ID );
884 popup->removeItem( 9024 ); // "Open"
885 if ( needToPublish <= 0 )
886 popup->removeItem( 804 ); // "Add in Study"
889 popup->removeItem( 803 ); // "Display Mode"
890 popup->removeItem( 8032 ); // "Color"
891 popup->removeItem( 8033 ); // "Transparency"
892 popup->removeItem( 8034 ); // "Isos"
893 popup->removeItem( QAD_DisplayOnly_Popup_ID );
897 popup->removeItem( QAD_Display_Popup_ID );
899 popup->removeItem( QAD_Erase_Popup_ID );
901 popup->removeItem( 8034 ); // "Isos"
906 // check popup for unnecessary separators
907 QAD_Tools::checkPopup( popup );
908 // find popup menu's TopLabel item (with title)
909 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
910 if ( topItem >= 0 ) {
911 // remove popup menu's title item
912 popup->removeItem( QAD_TopLabel_Popup_ID );
913 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
914 // set bold font for popup menu's title
915 QFont f = popup->font(); f.setBold( TRUE );
916 popup->removeItem( QAD_TopLabel_Popup_ID );
917 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
924 //=================================================================================
925 // function : GeometryGUI::ActiveStudyChanged()
927 //=================================================================================
928 bool GeometryGUI::ActiveStudyChanged(QAD_Desktop* parent)
930 GeometryGUI* geomGUI = GetGeomGUI();
931 QAD_Study* ActiveStudy = parent->getActiveStudy();
932 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
934 bool ViewOCC = false;
936 if( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
937 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
938 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
939 DisplayMode = ic->DisplayMode();
942 else if( ActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
943 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)ActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
944 DisplayMode = myRenderInter->GetDisplayMode();
947 if( DisplayMode == 1 )
948 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
950 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
952 //Mb->setItemEnabled( 404, ViewOCC ); // SKETCHER
953 Mb->setItemEnabled( 603, ViewOCC ); // SuppressFace
954 Mb->setItemEnabled( 604, ViewOCC ); // SuppressHole
955 Mb->setItemEnabled( 606, ViewOCC ); // CloseContour
956 Mb->setItemEnabled( 413, ViewOCC ); // Isos Settings
957 Mb->setItemEnabled( 800, ViewOCC ); // Create Group
958 Mb->setItemEnabled( 801, ViewOCC ); // Edit Group
959 Mb->setItemEnabled(9998, ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
961 geomGUI->EmitSignalCloseAllDialogs();
963 // PAL5356: update VTK selection
964 ::UpdateVtkSelection( parent );
968 for ( it = geomGUI->myGUIMap.begin(); it != geomGUI->myGUIMap.end(); ++it )
969 bOk = bOk && it.data()->ActiveStudyChanged( parent );
973 //=======================================================================
974 // function : GeometryGUI::BuildPresentation()
976 //=======================================================================
977 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO,
978 QAD_ViewFrame* theViewFrame )
980 GEOM_Displayer().Display( theIO, false, theViewFrame );
983 void GeometryGUI::SupportedViewType(int* buffer, int bufferSize)
985 if(!buffer || !bufferSize) return;
986 buffer[0] = (int)VIEW_OCC;
987 if (--bufferSize) buffer[1] = (int)VIEW_VTK;