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"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ViewManager.h>
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
43 #include <VTKViewer_ViewWindow.h>
44 #include <SVTK_RenderWindowInteractor.h>
45 #include <SVTK_InteractorStyle.h>
46 #include <SVTK_ViewModel.h>
47 #include <VTKViewer_ViewManager.h>
49 #include <SalomeApp_Application.h>
50 #include <SalomeApp_SelectionMgr.h>
51 #include <SalomeApp_VTKSelector.h>
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Preferences.h>
54 #include <SALOME_LifeCycleCORBA.hxx>
55 #include <SALOME_ListIO.hxx>
58 #include <qfileinfo.h>
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <OSD_SharedLibrary.hxx>
65 #include <utilities.h>
67 #include <vtkCamera.h>
68 #include <vtkRenderer.h>
72 Standard_EXPORT CAM_Module* createModule() {
73 return new GeometryGUI();
79 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
81 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen() { return GeometryGUI::myComponentGeom; }
83 bool GeometryGUI::InitGeomGen()
86 if( CORBA::is_nil( myComponentGeom ) ) return false;
90 //=======================================================================
91 // function : ClientSObjectToObject
93 //=======================================================================
94 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
96 _PTR(GenericAttribute) anAttr;
97 CORBA::Object_var anObj;
99 std::string aValue = theSObject->GetIOR();
100 if (strcmp(aValue.c_str(), "") != 0) {
101 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
102 anObj = anORB->string_to_object(aValue.c_str());
105 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
107 return anObj._retn();
110 //=======================================================================
111 // function : ClientStudyToStudy
113 //=======================================================================
114 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
116 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
117 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
118 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
119 int aStudyID = theStudy->StudyId();
120 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
121 return aDSStudy._retn();
124 //=================================================================================
125 // class : CustomItem
126 // purpose : Set Font to a text.
127 //=================================================================================
128 class CustomItem : public QCustomMenuItem
131 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
134 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
137 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
138 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
139 p->setFont( myFont );
140 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
146 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
149 bool fullSpan() const
159 //=======================================================================
160 // function : GeometryGUI::GeometryGUI()
161 // purpose : Constructor
162 //=======================================================================
163 GeometryGUI::GeometryGUI() :
164 SalomeApp_Module( "GEOM" )
166 if ( CORBA::is_nil( myComponentGeom ) )
168 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
169 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
170 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
174 myActiveDialogBox = 0;
177 gp_Pnt origin = gp_Pnt(0., 0., 0.);
178 gp_Dir direction = gp_Dir(0., 0., 1.);
179 myWorkingPlane = gp_Ax3(origin, direction);
181 myOCCSelectors.setAutoDelete( true );
182 myVTKSelectors.setAutoDelete( true );
185 //=======================================================================
186 // function : GeometryGUI::~GeometryGUI()
187 // purpose : Destructor
188 //=======================================================================
189 GeometryGUI::~GeometryGUI()
193 //=======================================================================
194 // function : GeometryGUI::getLibrary()
195 // purpose : get or load GUI library by name [ internal ]
196 //=======================================================================
197 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
198 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
200 if ( !myGUIMap.contains( libraryName ) ) {
201 // try to load library if it is not loaded yet
204 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
205 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
207 if( ( libs = getenv( "PATH" ) ) ) {
208 QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries
210 for( int i = dirList.count()-1; i >= 0; i-- ) {
211 QString dir = dirList[ i ];
212 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
214 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
215 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
217 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
218 continue; // continue search further
220 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
221 if ( osdF != NULL ) {
222 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
223 GEOMGUI* libGUI = (*func)(this);
225 myGUIMap[ libraryName ] = libGUI;
226 break; // found and loaded!
233 if ( myGUIMap.contains( libraryName ) )
234 // library is successfully loaded
235 return myGUIMap[ libraryName ];
239 //=======================================================================
240 // function : GeometryGUI::ActiveWorkingPlane()
241 // purpose : Activate Working Plane View
242 //=======================================================================
243 void GeometryGUI::ActiveWorkingPlane()
245 gp_Dir DZ = myWorkingPlane.Direction();
246 gp_Dir DY = myWorkingPlane.YDirection();
248 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
249 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
250 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
253 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
255 Handle(V3d_View) view3d = vw->getViewPort()->getView();
257 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
258 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
264 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
266 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
268 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
269 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
270 camera->SetFocalPoint(0,0,0);
277 //=======================================================================
278 // function : GeometryGUI::SetActiveDialogBox()
279 // purpose : Set active dialog box
280 //=======================================================================
281 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
283 myActiveDialogBox = (QDialog*)aDlg;
286 //=======================================================================
287 // function : GeometryGUI::EmitSignalDeactivateDialog()
288 // purpose : Emit a signal to deactivate the active dialog Box
289 //=======================================================================
290 void GeometryGUI::EmitSignalDeactivateDialog()
292 emit SignalDeactivateActiveDialog();
295 //=======================================================================
296 // function : GeometryGUI::EmitSignalCloseAllDialogs()
297 // purpose : Emit a signal to close all non modal dialogs box
298 //=======================================================================
299 void GeometryGUI::EmitSignalCloseAllDialogs()
301 emit SignalCloseAllDialogs();
304 //=======================================================================
305 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
306 // purpose : Emit a signal to inform that default real spin box step has
308 //=======================================================================
309 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
311 emit SignalDefaultStepValueChanged(newVal);
314 //=======================================================================
315 // function : GeometryGUI::OnGUIEvent()
316 // purpose : common slot for all menu/toolbar actions
317 //=======================================================================
318 void GeometryGUI::OnGUIEvent()
320 const QObject* obj = sender();
321 if ( !obj || !obj->inherits( "QAction" ) )
323 int id = actionId((QAction*)obj);
328 //=======================================================================
329 // function : GeometryGUI::OnGUIEvent()
330 // purpose : manage all events on GUI [static]
331 //=======================================================================
332 void GeometryGUI::OnGUIEvent( int id )
334 SUIT_Desktop* desk = application()->desktop();
336 // check type of the active viewframe
337 SUIT_ViewWindow* window = desk->activeWindow();
338 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
339 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
340 // if current viewframe is not of OCC and not of VTK type - return immediately
341 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
342 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
343 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
346 // fix for IPAL9103, point 2
347 if ( CORBA::is_nil( GetGeomGen() ) ) {
348 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
352 GEOMGUI* library = 0;
353 // try to get-or-load corresponding GUI library
354 if( id == 111 || // MENU FILE - IMPORT BREP
355 id == 112 || // MENU FILE - IMPORT IGES
356 id == 113 || // MENU FILE - IMPORT STEP
357 id == 121 || // MENU FILE - EXPORT BREP
358 id == 122 || // MENU FILE - EXPORT IGES
359 id == 123 || // MENU FILE - EXPORT STEP
360 id == 31 || // MENU EDIT - COPY
361 id == 33 || // MENU EDIT - DELETE
362 id == 411 || // MENU SETTINGS - ADD IN STUDY
363 id == 412 || // MENU SETTINGS - SHADING COLOR
364 id == 413 || // MENU SETTINGS - ISOS
365 id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
366 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
367 id == 8032 || // POPUP VIEWER - COLOR
368 id == 8033 || // POPUP VIEWER - TRANSPARENCY
369 id == 8034 || // POPUP VIEWER - ISOS
370 id == 804 || // POPUP VIEWER - ADD IN STUDY
371 id == 901 || // OBJECT BROWSER - RENAME
372 id == 9024 ) { // OBJECT BROWSER - OPEN
373 //cout << "id " << id << " received" << endl;
375 library = getLibrary( "libGEOMToolsGUI.so" );
377 library = getLibrary( "GEOMToolsGUI.dll" );
380 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
381 id == 212 || // MENU VIEW - DISPLAY ALL
382 id == 213 || // MENU VIEW - DISPLAY ONLY
383 id == 214 || // MENU VIEW - ERASE ALL
384 id == 215 || // MENU VIEW - ERASE
385 id == 216 || // MENU VIEW - DISPLAY
386 id == 80311 || // POPUP VIEWER - WIREFRAME
387 id == 80312 ) { // POPUP VIEWER - SHADING
389 library = getLibrary( "libDisplayGUI.so" );
391 library = getLibrary( "DisplayGUI.dll" );
394 else if( id == 4011 || // MENU BASIC - POINT
395 id == 4012 || // MENU BASIC - LINE
396 id == 4013 || // MENU BASIC - CIRCLE
397 id == 4014 || // MENU BASIC - ELLIPSE
398 id == 4015 || // MENU BASIC - ARC
399 id == 4016 || // MENU BASIC - VECTOR
400 id == 4017 || // MENU BASIC - PLANE
401 id == 4018 || // MENU BASIC - WPLANE
402 id == 4019 || // MENU BASIC - CURVE
403 id == 4020 ) { // MENU BASIC - REPAIR
405 library = getLibrary( "libBasicGUI.so" );
407 library = getLibrary( "BasicGUI.dll" );
410 else if( id == 4021 || // MENU PRIMITIVE - BOX
411 id == 4022 || // MENU PRIMITIVE - CYLINDER
412 id == 4023 || // MENU PRIMITIVE - SPHERE
413 id == 4024 || // MENU PRIMITIVE - TORUS
414 id == 4025 ) { // MENU PRIMITIVE - CONE
416 library = getLibrary( "libPrimitiveGUI.so" );
418 library = getLibrary( "PrimitiveGUI.dll" );
421 else if( id == 4031 || // MENU GENERATION - PRISM
422 id == 4032 || // MENU GENERATION - REVOLUTION
423 id == 4033 || // MENU GENERATION - FILLING
424 id == 4034 ) { // MENU GENERATION - PIPE
426 library = getLibrary( "libGenerationGUI.so" );
428 library = getLibrary( "GenerationGUI.dll" );
431 else if( id == 404 || // MENU ENTITY - SKETCHER
432 id == 407 ) { // MENU ENTITY - EXPLODE
434 library = getLibrary( "libEntityGUI.so" );
436 library = getLibrary( "EntityGUI.dll" );
439 else if( id == 4081 || // MENU BUILD - EDGE
440 id == 4082 || // MENU BUILD - WIRE
441 id == 4083 || // MENU BUILD - FACE
442 id == 4084 || // MENU BUILD - SHELL
443 id == 4085 || // MENU BUILD - SOLID
444 id == 4086 ) { // MENU BUILD - COMPUND
446 library = getLibrary( "libBuildGUI.so" );
448 library = getLibrary( "BuildGUI.dll" );
451 else if( id == 5011 || // MENU BOOLEAN - FUSE
452 id == 5012 || // MENU BOOLEAN - COMMON
453 id == 5013 || // MENU BOOLEAN - CUT
454 id == 5014 ) { // MENU BOOLEAN - SECTION
456 library = getLibrary( "libBooleanGUI.so" );
458 library = getLibrary( "BooleanGUI.dll" );
461 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
462 id == 5022 || // MENU TRANSFORMATION - ROTATION
463 id == 5023 || // MENU TRANSFORMATION - LOCATION
464 id == 5024 || // MENU TRANSFORMATION - MIRROR
465 id == 5025 || // MENU TRANSFORMATION - SCALE
466 id == 5026 || // MENU TRANSFORMATION - OFFSET
467 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
468 id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
470 library = getLibrary( "libTransformationGUI.so" );
472 library = getLibrary( "TransformationGUI.dll" );
475 else if( id == 503 || // MENU OPERATION - PARTITION
476 id == 504 || // MENU OPERATION - ARCHIMEDE
477 id == 505 || // MENU OPERATION - FILLET
478 id == 506 || // MENU OPERATION - CHAMFER
479 id == 507 ) { // MENU OPERATION - CLIPPING RANGE
481 library = getLibrary( "libOperationGUI.so" );
483 library = getLibrary( "OperationGUI.dll" );
486 else if( id == 601 || // MENU REPAIR - SEWING
487 id == 603 || // MENU REPAIR - SUPPRESS FACES
488 id == 604 || // MENU REPAIR - SUPPRESS HOLE
489 id == 605 || // MENU REPAIR - SHAPE PROCESSING
490 id == 606 || // MENU REPAIR - CLOSE CONTOUR
491 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
492 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
493 id == 609 || // MENU REPAIR - FREE BOUNDARIES
494 id == 610 || // MENU REPAIR - FREE FACES
495 id == 602 ) { // MENU REPAIR - GLUE FACES
497 library = getLibrary( "libRepairGUI.so" );
499 library = getLibrary( "RepairGUI.dll" );
502 else if( id == 701 || // MENU MEASURE - PROPERTIES
503 id == 702 || // MENU MEASURE - CDG
504 id == 703 || // MENU MEASURE - INERTIA
505 id == 7041 || // MENU MEASURE - BOUNDING BOX
506 id == 7042 || // MENU MEASURE - MIN DISTANCE
507 id == 705 || // MENU MEASURE - TOLERANCE
508 id == 706 || // MENU MEASURE - WHATIS
509 id == 707 || // MENU MEASURE - CHECK
510 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
511 id == 708 ) { // MENU MEASURE - POINT COORDINATES
513 library = getLibrary( "libMeasureGUI.so" );
515 library = getLibrary( "MeasureGUI.dll" );
518 else if( id == 800 || // MENU GROUP - CREATE
519 id == 8001 || // POPUP MENU - CREATE GROUP
520 id == 801 ) { // MENU GROUP - EDIT
522 library = getLibrary( "libGroupGUI.so" );
524 library = getLibrary( "GroupGUI.dll" );
527 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
528 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
529 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
530 id == 99991 || // MENU BLOCKS - PROPAGATE
531 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
533 library = getLibrary( "libBlocksGUI.so" );
535 library = getLibrary( "BlocksGUI.dll" );
539 // call method of corresponding GUI library
541 library->OnGUIEvent( id, desk );
543 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
547 //=================================================================================
548 // function : GeometryGUI::OnKeyPress()
549 // purpose : Called when any key is pressed by user [static]
550 //=================================================================================
551 bool GeometryGUI::OnKeyPress( QKeyEvent* pe, SUIT_ViewWindow* win )
555 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
556 bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
561 //=================================================================================
562 // function : GeometryGUI::OnMouseMove()
563 // purpose : Manages mouse move events [static]
564 //=================================================================================
565 bool GeometryGUI::OnMouseMove( QMouseEvent* pe, SUIT_ViewWindow* win )
569 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
570 bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
575 //=================================================================================
576 // function : GeometryGUI::0nMousePress()
577 // purpose : Manage mouse press events [static]
578 //=================================================================================
579 bool GeometryGUI::OnMousePress( QMouseEvent* pe, SUIT_ViewWindow* win )
582 // OnMousePress() should return false if this event should be processed further
583 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
584 bool processed = false;
585 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
586 processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
591 static void UpdateVtkSelection()
593 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
594 SUIT_ViewWindow* win = 0;
595 for ( win = winList.first(); win; win = winList.next() ) {
596 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
597 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
599 VTKViewer_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
600 anInteractor->SetSelectionProp();
601 anInteractor->SetSelectionTolerance();
602 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
604 aStyle->setPreselectionProp();
611 //=================================================================================
612 // function : GeometryGUI::SetSettings()
613 // purpose : Called when GEOM module is activated [static]
614 //=================================================================================
615 bool GeometryGUI::SetSettings()
617 QMenuBar* Mb = parent->getMainMenuBar();
618 SUIT_Study* ActiveStudy = application()->activeStudy();
620 // Wireframe or Shading
622 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
623 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
624 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
626 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
628 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
629 DisplayMode = ic->DisplayMode();
632 else if ( ViewVTK ) {
633 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
635 VTKViewer_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
636 DisplayMode = myRenderInter->GetDisplayMode();
640 if( DisplayMode == 1 )
642 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
644 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
647 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
648 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
649 int Settings_AddInStudy;
650 // if(!AddInStudy.isEmpty())
651 // Settings_AddInStudy = AddInStudy.toInt();
654 Settings_AddInStudy = 1;
655 Mb->setItemChecked(411, Settings_AddInStudy);
658 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
660 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
663 int count = ActiveStudy->getStudyFramesCount();
664 for(int i = 0; i < count; i++) {
665 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
666 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
667 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
669 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
670 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
672 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
674 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
680 // PAL5356: update VTK selection
681 ::UpdateVtkSelection();
684 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
685 bOk = bOk && it.data()->SetSettings( parent );
687 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
688 if (getenv( "GEOM_CLIPPING" ) == NULL)
690 QMenuItem* mi = Mb->findItem(50);
691 if (mi && mi->popup())
692 mi->popup()->removeItem(507);
699 //=======================================================================
700 // function : createGeomAction
702 //=======================================================================
703 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
706 QWidget* parent = application()->desktop();
707 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
709 if ( icon_id.length() )
710 pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
712 pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
714 icon = QIconSet( pix );
716 QString tooltip = tr( QString( "TOP_" )+po_id ),
717 menu = tr( QString( "MEN_" )+po_id ),
718 status_bar = tr( QString( "STB_" )+po_id );
720 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
725 //=======================================================================
726 // function : GeometryGUI::Deactivate()
727 // purpose : Called when GEOM module is deactivated [ static ]
728 //=======================================================================
729 void GeometryGUI::initialize( CAM_Application* app )
731 SalomeApp_Module::initialize( app );
733 // ----- create actions --------------
735 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
736 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
738 createGeomAction( 33, "DELETE" );
740 createGeomAction( 4011, "POINT" );
741 createGeomAction( 4012, "LINE" );
742 createGeomAction( 4013, "CIRCLE" );
743 createGeomAction( 4014, "ELLIPSE" );
744 createGeomAction( 4015, "ARC" );
745 createGeomAction( 4019, "CURVE" );
746 createGeomAction( 4016, "VECTOR" );
747 createGeomAction( 4017, "PLANE" );
748 createGeomAction( 4018, "WORK_PLANE" );
749 createGeomAction( 4020, "LOCAL_CS" );
751 createGeomAction( 4021, "BOX" );
752 createGeomAction( 4022, "CYLINDER" );
753 createGeomAction( 4023, "SPHERE" );
754 createGeomAction( 4024, "TORUS" );
755 createGeomAction( 4025, "CONE" );
757 createGeomAction( 4031, "EXTRUSION" );
758 createGeomAction( 4032, "REVOLUTION" );
759 createGeomAction( 4033, "FILLING" );
760 createGeomAction( 4034, "PIPE" );
762 createGeomAction( 800, "GROUP_CREATE" );
763 createGeomAction( 801, "GROUP_EDIT" );
765 createGeomAction( 9997, "Q_FACE" );
766 createGeomAction( 9999, "HEX_SOLID" );
768 createGeomAction( 404, "SKETCH" );
769 createGeomAction( 407, "EXPLODE" );
771 createGeomAction( 4081, "EDGE" );
772 createGeomAction( 4082, "WIRE" );
773 createGeomAction( 4083, "FACE" );
774 createGeomAction( 4084, "SHELL" );
775 createGeomAction( 4085, "SOLID" );
776 createGeomAction( 4086, "COMPOUND" );
778 createGeomAction( 5011, "FUSE" );
779 createGeomAction( 5012, "COMMON" );
780 createGeomAction( 5013, "CUT" );
781 createGeomAction( 5014, "SECTION" );
783 createGeomAction( 5021, "TRANSLATION" );
784 createGeomAction( 5022, "ROTATION" );
785 createGeomAction( 5023, "MODIFY_LOCATION" );
786 createGeomAction( 5024, "MIRROR" );
787 createGeomAction( 5025, "SCALE" );
788 createGeomAction( 5026, "OFFSET" );
789 createGeomAction( 5027, "MUL_TRANSLATION" );
790 createGeomAction( 5028, "MUL_ROTATION" );
792 createGeomAction( 503, "PARTITION" );
793 createGeomAction( 504, "ARCHIMEDE" );
794 createGeomAction( 505, "FILLET" );
795 createGeomAction( 506, "CHAMFER" );
796 //createGeomAction( 507, "CLIPPING" );
798 createGeomAction( 9998, "MUL_TRANSFORM" );
799 createGeomAction( 9995, "EXPLODE_BLOCKS" );
800 createGeomAction( 99991, "PROPAGATE" );
802 createGeomAction( 601, "SEWING" );
803 createGeomAction( 602, "GLUE_FACES" );
804 createGeomAction( 603, "SUPPRESS_FACES" );
805 createGeomAction( 604, "SUPPERSS_HOLES" );
806 createGeomAction( 605, "SHAPE_PROCESS" );
807 createGeomAction( 606, "CLOSE_CONTOUR" );
808 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
809 createGeomAction( 608, "POINT_ON_EDGE" );
810 createGeomAction( 609, "CHECK_FREE_BNDS" );
811 createGeomAction( 610, "CHECK_FREE_FACES" );
813 createGeomAction( 708, "POINT_COORDS" );
814 createGeomAction( 701, "BASIC_PROPS" );
815 createGeomAction( 702, "MASS_CENTER" );
816 createGeomAction( 703, "INERTIA" );
817 createGeomAction( 7041, "BND_BOX" );
818 createGeomAction( 7042, "MIN_DIST" );
820 createGeomAction( 705, "TOLERANCE" );
821 createGeomAction( 706, "WHAT_IS" );
822 createGeomAction( 707, "CHECK" );
823 createGeomAction( 7072, "CHECK_COMPOUND" );
825 createGeomAction( 5103, "CHECK_GEOMETRY" );
827 createGeomAction( 412, "SHADING_COLOR" );
828 createGeomAction( 413, "ISOS" );
829 createGeomAction( 414, "STEP_VALUE" );
831 createGeomAction( 211, "SHADING" );
832 createGeomAction( 212, "DISPLAY_ALL" );
833 createGeomAction( 214, "ERASE_ALL" );
834 createGeomAction( 216, "DISPLAY" );
835 createGeomAction( 213, "DISPLAY_ONLY" );
836 createGeomAction( 215, "ERASE" );
838 createGeomAction( 901, "POP_RENAME" );
839 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
840 createGeomAction( 80312, "POP_SHADING", "", 0, true );
841 createGeomAction( 8032, "POP_COLOR" );
842 createGeomAction( 8033, "POP_TRANSPARENCY" );
843 createGeomAction( 8034, "POP_ISOS" );
844 createGeomAction( 8001, "POP_CREATE_GROUP" );
846 // make wireframe-shading items to be exclusive (only one at a time is selected)
847 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
848 //dispModeGr->add( action( 80311 ) );
849 //dispModeGr->add( action( 80312 ) );
850 // ---- create menu --------------------------
852 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
853 createMenu( separator(), fileId, 10 );
854 createMenu( 111, fileId, 10 );
855 createMenu( 121, fileId, 10 );
856 createMenu( separator(), fileId, -1 );
858 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
859 createMenu( 33, editId, -1 );
861 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
863 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
864 createMenu( 4011, basicId, -1 );
865 createMenu( 4012, basicId, -1 );
866 createMenu( 4013, basicId, -1 );
867 createMenu( 4014, basicId, -1 );
868 createMenu( 4015, basicId, -1 );
869 createMenu( 4019, basicId, -1 );
870 createMenu( separator(), basicId, -1 );
871 createMenu( 4016, basicId, -1 );
872 createMenu( 4017, basicId, -1 );
873 createMenu( 4018, basicId, -1 );
874 createMenu( 4020, basicId, -1 );
876 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
877 createMenu( 4021, primId, -1 );
878 createMenu( 4022, primId, -1 );
879 createMenu( 4023, primId, -1 );
880 createMenu( 4024, primId, -1 );
881 createMenu( 4025, primId, -1 );
883 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
884 createMenu( 4031, genId, -1 );
885 createMenu( 4032, genId, -1 );
886 createMenu( 4033, genId, -1 );
887 createMenu( 4034, genId, -1 );
888 createMenu( separator(), newEntId, -1 );
890 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
891 createMenu( 800, groupId, -1 );
892 createMenu( 801, groupId, -1 );
893 createMenu( separator(), newEntId, -1 );
895 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
896 createMenu( 9997, blocksId, -1 );
897 createMenu( 9999, blocksId, -1 );
899 createMenu( separator(), newEntId, -1 );
900 createMenu( 404, newEntId, -1 );
901 createMenu( separator(), newEntId, -1 );
902 createMenu( 407, newEntId, -1 );
904 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
905 createMenu( 4081, buildId, -1 );
906 createMenu( 4082, buildId, -1 );
907 createMenu( 4083, buildId, -1 );
908 createMenu( 4084, buildId, -1 );
909 createMenu( 4085, buildId, -1 );
910 createMenu( 4086, buildId, -1 );
912 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
914 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
915 createMenu( 5011, boolId, -1 );
916 createMenu( 5012, boolId, -1 );
917 createMenu( 5013, boolId, -1 );
918 createMenu( 5014, boolId, -1 );
920 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
921 createMenu( 5021, transId, -1 );
922 createMenu( 5022, transId, -1 );
923 createMenu( 5023, transId, -1 );
924 createMenu( 5024, transId, -1 );
925 createMenu( 5025, transId, -1 );
926 createMenu( 5026, transId, -1 );
927 createMenu( separator(), transId, -1 );
928 createMenu( 5027, transId, -1 );
929 createMenu( 5028, transId, -1 );
931 createMenu( 503, operId, -1 );
932 createMenu( 504, operId, -1 );
933 createMenu( separator(), operId, -1 );
934 createMenu( 505, transId, -1 );
935 createMenu( 506, transId, -1 );
936 //createMenu( 507, transId, -1 );
938 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
939 createMenu( 9998, blockId, -1 );
940 createMenu( 9995, blockId, -1 );
941 createMenu( 99991, blockId, -1 );
943 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
944 createMenu( 605, repairId, -1 );
945 createMenu( 603, repairId, -1 );
946 createMenu( 606, repairId, -1 );
947 createMenu( 607, repairId, -1 );
948 createMenu( 604, repairId, -1 );
949 createMenu( 601, repairId, -1 );
950 createMenu( 602, repairId, -1 );
951 createMenu( 608, repairId, -1 );
952 createMenu( 609, repairId, -1 );
953 createMenu( 610, repairId, -1 );
955 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
956 createMenu( 708, measurId, -1 );
957 createMenu( 701, measurId, -1 );
958 createMenu( separator(), measurId, -1 );
959 createMenu( 702, measurId, -1 );
960 createMenu( 703, measurId, -1 );
961 createMenu( separator(), measurId, -1 );
963 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
964 createMenu( 7041, dimId, -1 );
965 createMenu( 7042, dimId, -1 );
966 createMenu( separator(), measurId, -1 );
968 createMenu( 705, measurId, -1 );
969 createMenu( separator(), measurId, -1 );
970 createMenu( 706, measurId, -1 );
971 createMenu( 707, measurId, -1 );
972 createMenu( 7072, measurId, -1 );
974 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
975 createMenu( separator(), toolsId, -1 );
976 createMenu( 5103, toolsId, -1 );
978 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
979 //createMenu( separator(), prefId, -1 );
980 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
981 //createMenu( 412, geomId, -1 );
982 //createMenu( 413, geomId, -1 );
983 //createMenu( 414, geomId, -1 );
984 //createMenu( separator(), prefId, -1 );
986 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
987 createMenu( separator(), viewId, -1 );
989 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
990 createMenu( 211, dispmodeId, -1 );
992 createMenu( separator(), viewId, -1 );
993 createMenu( 212, viewId, -1 );
994 createMenu( 214, viewId, -1 );
995 createMenu( separator(), viewId, -1 );
996 createMenu( 216, viewId, -1 );
997 createMenu( 213, viewId, -1 );
998 createMenu( 215, viewId, -1 );
1000 // ---- create toolbars --------------------------
1002 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1003 createTool( 4011, basicTbId );
1004 createTool( 4012, basicTbId );
1005 createTool( 4013, basicTbId );
1006 createTool( 4014, basicTbId );
1007 createTool( 4015, basicTbId );
1008 createTool( 4019, basicTbId );
1009 createTool( 4016, basicTbId );
1010 createTool( 4017, basicTbId );
1011 createTool( 4018, basicTbId );
1012 createTool( 4020, basicTbId );
1014 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1015 createTool( 4021, primTbId );
1016 createTool( 4022, primTbId );
1017 createTool( 4023, primTbId );
1018 createTool( 4024, primTbId );
1019 createTool( 4025, primTbId );
1021 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1022 createTool( 5011, boolTbId );
1023 createTool( 5012, boolTbId );
1024 createTool( 5013, boolTbId );
1025 createTool( 5014, boolTbId );
1027 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1028 createTool( 4031, genTbId );
1029 createTool( 4032, genTbId );
1030 createTool( 4033, genTbId );
1031 createTool( 4034, genTbId );
1033 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1034 createTool( 5021, transTbId );
1035 createTool( 5022, transTbId );
1036 createTool( 5023, transTbId );
1037 createTool( 5024, transTbId );
1038 createTool( 5025, transTbId );
1039 createTool( 5026, transTbId );
1040 createTool( separator(), transTbId );
1041 createTool( 5027, transTbId );
1042 createTool( 5028, transTbId );
1044 QtxPopupMgr* mgr = popupMgr();
1045 mgr->insert( action( 901 ), -1, -1 ); // rename
1046 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1047 mgr->insert( action( 8001 ), -1, -1 ); // create group
1048 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1049 mgr->insert( action( 801 ), -1, -1 ); // edit group
1050 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1051 mgr->insert( separator(), -1, -1 ); // -----------
1052 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1053 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1054 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1055 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Wireframe'", false );
1056 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1057 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1058 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Shading'", false );
1059 mgr->insert( separator(), -1, -1 ); // -----------
1060 mgr->insert( action( 8032 ), -1, -1 ); // color
1061 mgr->setRule( action( 8032 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1062 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1063 mgr->setRule( action( 8033 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1064 mgr->insert( action( 8034 ), -1, -1 ); // isos
1065 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0", true );
1066 mgr->insert( separator(), -1, -1 ); // -----------
1067 mgr->insert( action( 216 ), -1, -1 ); // display
1068 mgr->setRule( action( 216 ), "(selcount>0) and (((isActiveView=true) and (($type in {'Shape' 'Group'} and isVisible=false) or type='Component'))"
1069 "or ((isActiveView=false) and ($type in {'Shape' 'Group' 'Component'})))", true );
1070 mgr->insert( action( 215 ), -1, -1 ); // erase
1071 mgr->setRule( action( 215 ), "(isActiveView=true) and (($type in {'Shape' 'Group'} and isVisible=true and selcount>0) or (type='Component' and selcount=1))", true );
1072 mgr->insert( action( 214 ), -1, -1 ); // erase All
1073 mgr->setRule( action( 214 ), "client='OCCViewer' or client='VTKViewer'", true );
1074 mgr->insert( action( 213 ), -1, -1 ); // display only
1075 mgr->setRule( action( 213 ), "($type in {'Shape' 'Group'} and selcount>0) or (type='Component' and selcount=1)", true );
1076 mgr->insert( separator(), -1, -1 );
1079 //=======================================================================
1080 // function : GeometryGUI::Deactivate()
1081 // purpose : Called when GEOM module is deactivated [ static ]
1082 //=======================================================================
1083 bool GeometryGUI::activateModule( SUIT_Study* study )
1085 if ( CORBA::is_nil( myComponentGeom ) )
1088 bool res = SalomeApp_Module::activateModule( study );
1093 setMenuShown( true );
1094 setToolShown( true );
1096 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1097 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1098 connect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1099 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1101 GUIMap::Iterator it;
1102 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1103 it.data()->activate( application()->desktop() );
1105 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1106 SUIT_ViewManager* vm;
1107 ViewManagerList OCCViewManagers, VTKViewManagers;
1108 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1109 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1110 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1111 application()->viewManagers( VTKViewer_Viewer::Type(), VTKViewManagers );
1112 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1113 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1115 // disable OCC selectors
1116 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1117 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1118 sr->setEnabled(true);
1120 // disable VTK selectors
1121 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1122 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1123 sr->setEnabled(true);
1129 //=======================================================================
1130 // function : GeometryGUI::Deactivate()
1131 // purpose : Called when GEOM module is deactivated [ static ]
1132 //=======================================================================
1133 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1135 setMenuShown( false );
1136 setToolShown( false );
1138 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1139 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1140 disconnect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1141 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1143 EmitSignalCloseAllDialogs();
1145 GUIMap::Iterator it;
1146 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1147 it.data()->deactivate();
1149 myOCCSelectors.clear();
1150 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1152 myVTKSelectors.clear();
1153 getApp()->selectionMgr()->setEnabled( true, VTKViewer_Viewer::Type() );
1155 return SalomeApp_Module::deactivateModule( study );
1158 //=================================================================================
1159 // function : GeometryGUI::DefinePopup()
1160 // purpose : Called from desktop to define popup menu [static]
1161 //=================================================================================
1163 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1165 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1166 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1171 if ( theParent == "Viewer" ) {
1172 if ( Sel->IObjectCount() == 0 )
1173 theContext = "NothingSelected";
1176 if ( Sel->IObjectCount() == 1 ) {
1177 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1178 if( IO->hasEntry() ) {
1179 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1180 if ( !sobj->_is_nil() ) {
1181 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1182 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1183 // component is selected
1184 theObject = "Component";
1187 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1188 if ( !CORBA::is_nil( aGObj ) ) {
1189 switch( aGObj->GetType() ) {
1191 theObject = "Group";
1194 theObject = "Shape";
1204 //=================================================================================
1205 // function : GeometryGUI::CustomPopup()
1206 // purpose : Called from desktop to create popup menu [static]
1207 //=================================================================================
1208 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1209 const QString& theParent, const QString& theObject)
1211 GeometryGUI* geomGUI = GetGeomGUI();
1213 // Deactivate any non modal dialog box to get the neutral point
1214 geomGUI->EmitSignalDeactivateDialog();
1215 QAD_Study* anActiveStudy = parent->getActiveStudy();
1216 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1217 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1218 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1219 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1220 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1221 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1222 int aDisplayMode = 0;
1225 if ( aViewFrame->getTypeView() == VIEW_OCC )
1226 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1227 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1228 aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
1230 int nbSel = Sel->IObjectCount();
1233 ////// NOTHING SELECTED
1236 else if ( nbSel == 1 ) {
1237 ////// SINGLE OBJECT SELECTION
1238 if ( parentComponent != parent->getActiveComponent() ) {
1239 ////// selected object does not belong to GEOM module:
1240 // remove all commands except Display/Erase...
1242 int id = popup->idAt( 0 );
1243 if ( id <= QAD_TopLabel_Popup_ID )
1244 popup->removeItemAt( 0 );
1250 ////// selected object belong to the GEOM module
1251 // get interactive object
1252 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1253 objectName = IObject->getName();
1254 // if object has entry get SObject
1255 SALOMEDS::SObject_var SO;
1256 if ( IObject->hasEntry() )
1257 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1259 if ( theObject == "Component" ) {
1260 ////// menu for component
1261 if ( !isOCCViewer && !isVTKViewer ) {
1262 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1263 popup->removeItem( QAD_Display_Popup_ID );
1264 popup->removeItem( QAD_Erase_Popup_ID );
1268 ////// not component (should be shape)
1269 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1270 popup->removeItem( 804 ); // "Add in Study"
1272 // Here could be analysis of the geom shape's type
1275 SALOMEDS::GenericAttribute_var aTmpAttr;
1276 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1277 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1279 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1280 if ( theObject == "Shape" )
1281 popup->removeItem( 800 ); // Create Group
1282 else if ( theObject == "Group" )
1283 popup->removeItem( 801 ); // Edit Group
1286 if ( isOCCViewer || isVTKViewer ) {
1287 ////// current viewer is OCC or VTK
1288 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1289 if ( aViewFrame->isVisible( IObject ) ) {
1290 ////// object is already displayed in the viewer
1291 popup->removeItem( QAD_Display_Popup_ID );
1292 if ( isOCCViewer ) {
1293 ////// OCC viewer only
1294 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1295 if ( occPrs && !occPrs->IsNull() ) {
1296 AIS_ListOfInteractive ioList;
1297 occPrs->GetObjects( ioList );
1298 QMenuItem* mi = popup->findItem( 803 );
1299 if ( mi && mi->popup() ) {
1300 if ( ioList.First()->DisplayMode() == 0 )
1301 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1302 else if ( ioList.First()->DisplayMode() == 1 )
1303 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1304 else if ( ioList.First()->DisplayMode() < 0 )
1305 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1310 ////// VTK viewer only
1311 popup->removeItem( 8034 ); // "Isos"
1312 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
1313 if ( vtkPrs && !vtkPrs->IsNull() ) {
1314 vtkActorCollection* actorList = vtkPrs->GetObjects();
1315 actorList->InitTraversal();
1316 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1317 QMenuItem* mi = popup->findItem( 803 );
1318 if ( ac && mi && mi->popup() ) {
1319 if ( ac->getDisplayMode() == 0 )
1320 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1321 else if ( ac->getDisplayMode() == 1 )
1322 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1324 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1330 ////// object is not yet displayed in the viewer
1331 popup->removeItem( 803 ); // "Display Mode"
1332 popup->removeItem( 8032 ); // "Color"
1333 popup->removeItem( 8033 ); // "Transparency"
1334 popup->removeItem( 8034 ); // "Isos"
1335 popup->removeItem( QAD_Erase_Popup_ID );
1340 ////// other viewer type (neither OCC nor VTK)
1341 popup->removeItem( 803 ); // "Display Mode"
1342 popup->removeItem( 8032 ); // "Color"
1343 popup->removeItem( 8033 ); // "Transparency"
1344 popup->removeItem( 8034 ); // "Isos"
1345 popup->removeItem( QAD_Display_Popup_ID );
1346 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1347 popup->removeItem( QAD_Erase_Popup_ID );
1353 ////// MULTIPLE SELECTION
1354 if ( parentComponent != parent->getActiveComponent() ) {
1355 ////// not GEOM module objects or objects belong to different modules
1356 // remove all commands except Display/Erase...
1358 int id = popup->idAt( 0 );
1359 if ( id <= QAD_TopLabel_Popup_ID )
1360 popup->removeItemAt( 0 );
1364 if ( parentComponent.isNull() ) {
1365 ////// objects belong to different modules
1366 popup->removeItem(QAD_Display_Popup_ID);
1367 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1368 popup->removeItem(QAD_Erase_Popup_ID);
1371 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1375 ////// all selected objects belong to GEOM module
1376 popup->removeItem( 901 ); // "Rename"
1378 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1379 bool isComponent = false;
1380 bool needOpen = false;
1381 bool needDisplay = false;
1382 bool needErase = false;
1383 int needToPublish = 0;
1385 for( ;It.More();It.Next() ) {
1386 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1388 if ( aViewFrame->isVisible( anIObject ) )
1393 if( anIObject->hasEntry() ) {
1394 needToPublish = -1; /////// VSR : TO BE REMOVED
1395 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1396 SALOMEDS::GenericAttribute_var aTmpAttr;
1397 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1398 needOpen = true; /////// VSR : TO BE REMOVED
1399 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1403 if ( needToPublish != -1 ) needToPublish = 1;
1406 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1407 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1408 popup->removeItem( 803 ); // "Display Mode"
1409 popup->removeItem( 8032 ); // "Color"
1410 popup->removeItem( 8033 ); // "Transparency"
1411 popup->removeItem( 8034 ); // "Isos"
1412 popup->removeItem( 804 ); // "Add in Study"
1413 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1414 popup->removeItem( QAD_Display_Popup_ID );
1415 popup->removeItem( QAD_Erase_Popup_ID );
1418 popup->removeItem( 9024 ); // "Open"
1419 if ( needToPublish <= 0 )
1420 popup->removeItem( 804 ); // "Add in Study"
1423 popup->removeItem( 803 ); // "Display Mode"
1424 popup->removeItem( 8032 ); // "Color"
1425 popup->removeItem( 8033 ); // "Transparency"
1426 popup->removeItem( 8034 ); // "Isos"
1427 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1431 popup->removeItem( QAD_Display_Popup_ID );
1433 popup->removeItem( QAD_Erase_Popup_ID );
1435 popup->removeItem( 8034 ); // "Isos"
1440 // check popup for unnecessary separators
1441 QAD_Tools::checkPopup( popup );
1442 // find popup menu's TopLabel item (with title)
1443 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1444 if ( topItem >= 0 ) {
1445 // remove popup menu's title item
1446 popup->removeItem( QAD_TopLabel_Popup_ID );
1447 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1448 // set bold font for popup menu's title
1449 QFont f = popup->font(); f.setBold( TRUE );
1450 popup->removeItem( QAD_TopLabel_Popup_ID );
1451 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1460 //=======================================================================
1461 // function : GeometryGUI::BuildPresentation()
1463 //=======================================================================
1464 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1466 //GEOM_Displayer().Display( io, false, win );
1469 //=======================================================================
1470 // function : setCommandsEnabled()
1471 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1472 //=======================================================================
1473 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1478 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1479 // const bool ViewVTK = ( win->getViewManager()->getType() == VTKViewer_Viewer::Type() );
1481 // disable non-OCC viewframe menu commands
1482 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1483 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1484 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1485 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1486 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1487 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1488 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1489 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1491 action( 800 )->setEnabled( ViewOCC ); // Create Group
1492 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1494 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1497 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1499 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1500 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1503 void GeometryGUI::viewManagers( QStringList& lst ) const
1505 lst.append( OCCViewer_Viewer::Type() );
1508 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1510 if ( vm->getType() == OCCViewer_Viewer::Type() )
1512 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1513 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1515 // disable OCC selectors
1516 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1517 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1518 sr->setEnabled(true);
1520 else if ( vm->getType() == VTKViewer_Viewer::Type() )
1522 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1523 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1525 // disable VTK selectors
1526 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1527 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1528 sr->setEnabled(true);
1532 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1534 SUIT_ViewModel* viewer = vm->getViewModel();
1535 if ( vm->getType() == OCCViewer_Viewer::Type() )
1537 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1538 if ( sr->viewer() == viewer )
1540 myOCCSelectors.remove( sr );
1544 if ( vm->getType() == VTKViewer_Viewer::Type() )
1546 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1547 if ( sr->viewer() == viewer )
1549 myVTKSelectors.remove( sr );
1555 QString GeometryGUI::engineIOR() const
1557 if ( !CORBA::is_nil( GetGeomGen() ) )
1558 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1559 return QString( "" );
1562 SalomeApp_Selection* GeometryGUI::createSelection() const
1564 return new GEOMGUI_Selection();
1567 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1569 SalomeApp_Module::contextMenuPopup( client, menu, title );
1571 getApp()->selectionMgr()->selectedObjects( lst );
1572 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1573 Handle(SALOME_InteractiveObject) io = lst.First();
1574 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1575 _PTR(Study) study = appStudy->studyDS();
1576 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1578 title = QString( obj->GetName().c_str() );
1582 void GeometryGUI::createPreferences()
1584 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1586 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1587 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1588 SalomeApp_Preferences::Color, "Geometry", "shading_color" );
1589 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1590 SalomeApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1591 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1592 SalomeApp_Preferences::Selector, "Geometry", "display_mode" );
1594 setPreferenceProperty( genGroup, "columns", 1 );
1596 setPreferenceProperty( step, "min", 0.001 );
1597 setPreferenceProperty( step, "max", 10000 );
1598 setPreferenceProperty( step, "precision", 3 );
1600 // Set property for default display mode
1601 QStringList aModesList;
1602 aModesList.append( tr("MEN_WIREFRAME") );
1603 aModesList.append( tr("MEN_SHADING") );
1605 QValueList<QVariant> anIndexesList;
1606 anIndexesList.append(0);
1607 anIndexesList.append(1);
1609 setPreferenceProperty( dispmode, "strings", aModesList );
1610 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1613 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )