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"
32 #include "GEOM_Displayer.h"
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewManager.h>
39 #include <OCCViewer_ViewWindow.h>
40 #include <OCCViewer_ViewPort3d.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewManager.h>
44 #include <VTKViewer_ViewWindow.h>
45 #include <SVTK_RenderWindowInteractor.h>
46 #include <SVTK_InteractorStyle.h>
47 #include <SVTK_ViewModel.h>
48 #include <VTKViewer_ViewManager.h>
50 #include <SalomeApp_Application.h>
51 #include <SalomeApp_SelectionMgr.h>
52 #include <SalomeApp_VTKSelector.h>
53 #include <SalomeApp_Study.h>
54 #include <SalomeApp_Preferences.h>
55 #include <SALOME_LifeCycleCORBA.hxx>
56 #include <SALOME_ListIO.hxx>
59 #include <qfileinfo.h>
62 #include <Prs3d_Drawer.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64 #include <OSD_SharedLibrary.hxx>
66 #include <utilities.h>
68 #include <vtkCamera.h>
69 #include <vtkRenderer.h>
73 Standard_EXPORT CAM_Module* createModule() {
74 return new GeometryGUI();
80 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
82 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen() { return GeometryGUI::myComponentGeom; }
84 bool GeometryGUI::InitGeomGen()
87 if( CORBA::is_nil( myComponentGeom ) ) return false;
91 //=======================================================================
92 // function : ClientSObjectToObject
94 //=======================================================================
95 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
97 _PTR(GenericAttribute) anAttr;
98 CORBA::Object_var anObj;
100 std::string aValue = theSObject->GetIOR();
101 if (strcmp(aValue.c_str(), "") != 0) {
102 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
103 anObj = anORB->string_to_object(aValue.c_str());
106 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
108 return anObj._retn();
111 //=======================================================================
112 // function : ClientStudyToStudy
114 //=======================================================================
115 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
117 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
118 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
119 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
120 int aStudyID = theStudy->StudyId();
121 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
122 return aDSStudy._retn();
125 //=================================================================================
126 // class : CustomItem
127 // purpose : Set Font to a text.
128 //=================================================================================
129 class CustomItem : public QCustomMenuItem
132 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
135 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
138 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
139 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
140 p->setFont( myFont );
141 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
147 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
150 bool fullSpan() const
160 //=======================================================================
161 // function : GeometryGUI::GeometryGUI()
162 // purpose : Constructor
163 //=======================================================================
164 GeometryGUI::GeometryGUI() :
165 SalomeApp_Module( "GEOM" )
167 if ( CORBA::is_nil( myComponentGeom ) )
169 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
170 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
171 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
175 myActiveDialogBox = 0;
178 gp_Pnt origin = gp_Pnt(0., 0., 0.);
179 gp_Dir direction = gp_Dir(0., 0., 1.);
180 myWorkingPlane = gp_Ax3(origin, direction);
182 myOCCSelectors.setAutoDelete( true );
183 myVTKSelectors.setAutoDelete( true );
188 //=======================================================================
189 // function : GeometryGUI::~GeometryGUI()
190 // purpose : Destructor
191 //=======================================================================
192 GeometryGUI::~GeometryGUI()
196 //=======================================================================
197 // function : GeometryGUI::getLibrary()
198 // purpose : get or load GUI library by name [ internal ]
199 //=======================================================================
200 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
201 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
203 if ( !myGUIMap.contains( libraryName ) ) {
204 // try to load library if it is not loaded yet
207 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
208 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
210 if( ( libs = getenv( "PATH" ) ) ) {
211 QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries
213 for( int i = dirList.count()-1; i >= 0; i-- ) {
214 QString dir = dirList[ i ];
215 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
217 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
218 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
220 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
221 continue; // continue search further
223 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
224 if ( osdF != NULL ) {
225 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
226 GEOMGUI* libGUI = (*func)(this);
228 myGUIMap[ libraryName ] = libGUI;
229 break; // found and loaded!
236 if ( myGUIMap.contains( libraryName ) )
237 // library is successfully loaded
238 return myGUIMap[ libraryName ];
242 //=======================================================================
243 // function : GeometryGUI::ActiveWorkingPlane()
244 // purpose : Activate Working Plane View
245 //=======================================================================
246 void GeometryGUI::ActiveWorkingPlane()
248 gp_Dir DZ = myWorkingPlane.Direction();
249 gp_Dir DY = myWorkingPlane.YDirection();
251 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
252 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
253 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
256 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
258 Handle(V3d_View) view3d = vw->getViewPort()->getView();
260 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
261 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
267 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
269 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
271 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
272 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
273 camera->SetFocalPoint(0,0,0);
280 //=======================================================================
281 // function : GeometryGUI::SetActiveDialogBox()
282 // purpose : Set active dialog box
283 //=======================================================================
284 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
286 myActiveDialogBox = (QDialog*)aDlg;
289 //=======================================================================
290 // function : GeometryGUI::EmitSignalDeactivateDialog()
291 // purpose : Emit a signal to deactivate the active dialog Box
292 //=======================================================================
293 void GeometryGUI::EmitSignalDeactivateDialog()
295 emit SignalDeactivateActiveDialog();
298 //=======================================================================
299 // function : GeometryGUI::EmitSignalCloseAllDialogs()
300 // purpose : Emit a signal to close all non modal dialogs box
301 //=======================================================================
302 void GeometryGUI::EmitSignalCloseAllDialogs()
304 emit SignalCloseAllDialogs();
307 //=======================================================================
308 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
309 // purpose : Emit a signal to inform that default real spin box step has
311 //=======================================================================
312 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
314 emit SignalDefaultStepValueChanged(newVal);
317 //=======================================================================
318 // function : GeometryGUI::OnGUIEvent()
319 // purpose : common slot for all menu/toolbar actions
320 //=======================================================================
321 void GeometryGUI::OnGUIEvent()
323 const QObject* obj = sender();
324 if ( !obj || !obj->inherits( "QAction" ) )
326 int id = actionId((QAction*)obj);
331 //=======================================================================
332 // function : GeometryGUI::OnGUIEvent()
333 // purpose : manage all events on GUI [static]
334 //=======================================================================
335 void GeometryGUI::OnGUIEvent( int id )
337 SUIT_Desktop* desk = application()->desktop();
339 // check type of the active viewframe
340 SUIT_ViewWindow* window = desk->activeWindow();
341 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
342 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
343 // if current viewframe is not of OCC and not of VTK type - return immediately
344 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
345 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
346 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
349 // fix for IPAL9103, point 2
350 if ( CORBA::is_nil( GetGeomGen() ) ) {
351 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
355 GEOMGUI* library = 0;
356 // try to get-or-load corresponding GUI library
357 if( id == 111 || // MENU FILE - IMPORT BREP
358 id == 112 || // MENU FILE - IMPORT IGES
359 id == 113 || // MENU FILE - IMPORT STEP
360 id == 121 || // MENU FILE - EXPORT BREP
361 id == 122 || // MENU FILE - EXPORT IGES
362 id == 123 || // MENU FILE - EXPORT STEP
363 id == 31 || // MENU EDIT - COPY
364 id == 33 || // MENU EDIT - DELETE
365 id == 411 || // MENU SETTINGS - ADD IN STUDY
366 id == 412 || // MENU SETTINGS - SHADING COLOR
367 id == 413 || // MENU SETTINGS - ISOS
368 id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
369 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
370 id == 8032 || // POPUP VIEWER - COLOR
371 id == 8033 || // POPUP VIEWER - TRANSPARENCY
372 id == 8034 || // POPUP VIEWER - ISOS
373 id == 804 || // POPUP VIEWER - ADD IN STUDY
374 id == 901 || // OBJECT BROWSER - RENAME
375 id == 9024 ) { // OBJECT BROWSER - OPEN
376 //cout << "id " << id << " received" << endl;
378 library = getLibrary( "libGEOMToolsGUI.so" );
380 library = getLibrary( "GEOMToolsGUI.dll" );
383 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
384 id == 212 || // MENU VIEW - DISPLAY ALL
385 id == 213 || // MENU VIEW - DISPLAY ONLY
386 id == 214 || // MENU VIEW - ERASE ALL
387 id == 215 || // MENU VIEW - ERASE
388 id == 216 || // MENU VIEW - DISPLAY
389 id == 80311 || // POPUP VIEWER - WIREFRAME
390 id == 80312 ) { // POPUP VIEWER - SHADING
392 library = getLibrary( "libDisplayGUI.so" );
394 library = getLibrary( "DisplayGUI.dll" );
397 else if( id == 4011 || // MENU BASIC - POINT
398 id == 4012 || // MENU BASIC - LINE
399 id == 4013 || // MENU BASIC - CIRCLE
400 id == 4014 || // MENU BASIC - ELLIPSE
401 id == 4015 || // MENU BASIC - ARC
402 id == 4016 || // MENU BASIC - VECTOR
403 id == 4017 || // MENU BASIC - PLANE
404 id == 4018 || // MENU BASIC - WPLANE
405 id == 4019 || // MENU BASIC - CURVE
406 id == 4020 ) { // MENU BASIC - REPAIR
408 library = getLibrary( "libBasicGUI.so" );
410 library = getLibrary( "BasicGUI.dll" );
413 else if( id == 4021 || // MENU PRIMITIVE - BOX
414 id == 4022 || // MENU PRIMITIVE - CYLINDER
415 id == 4023 || // MENU PRIMITIVE - SPHERE
416 id == 4024 || // MENU PRIMITIVE - TORUS
417 id == 4025 ) { // MENU PRIMITIVE - CONE
419 library = getLibrary( "libPrimitiveGUI.so" );
421 library = getLibrary( "PrimitiveGUI.dll" );
424 else if( id == 4031 || // MENU GENERATION - PRISM
425 id == 4032 || // MENU GENERATION - REVOLUTION
426 id == 4033 || // MENU GENERATION - FILLING
427 id == 4034 ) { // MENU GENERATION - PIPE
429 library = getLibrary( "libGenerationGUI.so" );
431 library = getLibrary( "GenerationGUI.dll" );
434 else if( id == 404 || // MENU ENTITY - SKETCHER
435 id == 407 ) { // MENU ENTITY - EXPLODE
437 library = getLibrary( "libEntityGUI.so" );
439 library = getLibrary( "EntityGUI.dll" );
442 else if( id == 4081 || // MENU BUILD - EDGE
443 id == 4082 || // MENU BUILD - WIRE
444 id == 4083 || // MENU BUILD - FACE
445 id == 4084 || // MENU BUILD - SHELL
446 id == 4085 || // MENU BUILD - SOLID
447 id == 4086 ) { // MENU BUILD - COMPUND
449 library = getLibrary( "libBuildGUI.so" );
451 library = getLibrary( "BuildGUI.dll" );
454 else if( id == 5011 || // MENU BOOLEAN - FUSE
455 id == 5012 || // MENU BOOLEAN - COMMON
456 id == 5013 || // MENU BOOLEAN - CUT
457 id == 5014 ) { // MENU BOOLEAN - SECTION
459 library = getLibrary( "libBooleanGUI.so" );
461 library = getLibrary( "BooleanGUI.dll" );
464 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
465 id == 5022 || // MENU TRANSFORMATION - ROTATION
466 id == 5023 || // MENU TRANSFORMATION - LOCATION
467 id == 5024 || // MENU TRANSFORMATION - MIRROR
468 id == 5025 || // MENU TRANSFORMATION - SCALE
469 id == 5026 || // MENU TRANSFORMATION - OFFSET
470 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
471 id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
473 library = getLibrary( "libTransformationGUI.so" );
475 library = getLibrary( "TransformationGUI.dll" );
478 else if( id == 503 || // MENU OPERATION - PARTITION
479 id == 504 || // MENU OPERATION - ARCHIMEDE
480 id == 505 || // MENU OPERATION - FILLET
481 id == 506 || // MENU OPERATION - CHAMFER
482 id == 507 ) { // MENU OPERATION - CLIPPING RANGE
484 library = getLibrary( "libOperationGUI.so" );
486 library = getLibrary( "OperationGUI.dll" );
489 else if( id == 601 || // MENU REPAIR - SEWING
490 id == 603 || // MENU REPAIR - SUPPRESS FACES
491 id == 604 || // MENU REPAIR - SUPPRESS HOLE
492 id == 605 || // MENU REPAIR - SHAPE PROCESSING
493 id == 606 || // MENU REPAIR - CLOSE CONTOUR
494 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
495 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
496 id == 609 || // MENU REPAIR - FREE BOUNDARIES
497 id == 610 || // MENU REPAIR - FREE FACES
498 id == 602 ) { // MENU REPAIR - GLUE FACES
500 library = getLibrary( "libRepairGUI.so" );
502 library = getLibrary( "RepairGUI.dll" );
505 else if( id == 701 || // MENU MEASURE - PROPERTIES
506 id == 702 || // MENU MEASURE - CDG
507 id == 703 || // MENU MEASURE - INERTIA
508 id == 7041 || // MENU MEASURE - BOUNDING BOX
509 id == 7042 || // MENU MEASURE - MIN DISTANCE
510 id == 705 || // MENU MEASURE - TOLERANCE
511 id == 706 || // MENU MEASURE - WHATIS
512 id == 707 || // MENU MEASURE - CHECK
513 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
514 id == 708 ) { // MENU MEASURE - POINT COORDINATES
516 library = getLibrary( "libMeasureGUI.so" );
518 library = getLibrary( "MeasureGUI.dll" );
521 else if( id == 800 || // MENU GROUP - CREATE
522 id == 8001 || // POPUP MENU - CREATE GROUP
523 id == 801 ) { // MENU GROUP - EDIT
525 library = getLibrary( "libGroupGUI.so" );
527 library = getLibrary( "GroupGUI.dll" );
530 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
531 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
532 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
533 id == 99991 || // MENU BLOCKS - PROPAGATE
534 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
536 library = getLibrary( "libBlocksGUI.so" );
538 library = getLibrary( "BlocksGUI.dll" );
542 // call method of corresponding GUI library
544 library->OnGUIEvent( id, desk );
546 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
550 //=================================================================================
551 // function : GeometryGUI::OnKeyPress()
552 // purpose : Called when any key is pressed by user [static]
553 //=================================================================================
554 bool GeometryGUI::OnKeyPress( QKeyEvent* pe, SUIT_ViewWindow* win )
558 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
559 bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
564 //=================================================================================
565 // function : GeometryGUI::OnMouseMove()
566 // purpose : Manages mouse move events [static]
567 //=================================================================================
568 bool GeometryGUI::OnMouseMove( QMouseEvent* pe, SUIT_ViewWindow* win )
572 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
573 bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
578 //=================================================================================
579 // function : GeometryGUI::0nMousePress()
580 // purpose : Manage mouse press events [static]
581 //=================================================================================
582 bool GeometryGUI::OnMousePress( QMouseEvent* pe, SUIT_ViewWindow* win )
585 // OnMousePress() should return false if this event should be processed further
586 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
587 bool processed = false;
588 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
589 processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
594 static void UpdateVtkSelection()
596 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
597 SUIT_ViewWindow* win = 0;
598 for ( win = winList.first(); win; win = winList.next() ) {
599 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
600 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
602 VTKViewer_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
603 anInteractor->SetSelectionProp();
604 anInteractor->SetSelectionTolerance();
605 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
607 aStyle->setPreselectionProp();
614 //=================================================================================
615 // function : GeometryGUI::SetSettings()
616 // purpose : Called when GEOM module is activated [static]
617 //=================================================================================
618 bool GeometryGUI::SetSettings()
620 QMenuBar* Mb = parent->getMainMenuBar();
621 SUIT_Study* ActiveStudy = application()->activeStudy();
623 // Wireframe or Shading
625 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
626 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
627 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
629 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
631 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
632 DisplayMode = ic->DisplayMode();
635 else if ( ViewVTK ) {
636 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
638 VTKViewer_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
639 DisplayMode = myRenderInter->GetDisplayMode();
643 if( DisplayMode == 1 )
645 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
647 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
650 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
651 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
652 int Settings_AddInStudy;
653 // if(!AddInStudy.isEmpty())
654 // Settings_AddInStudy = AddInStudy.toInt();
657 Settings_AddInStudy = 1;
658 Mb->setItemChecked(411, Settings_AddInStudy);
661 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
663 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
666 int count = ActiveStudy->getStudyFramesCount();
667 for(int i = 0; i < count; i++) {
668 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
669 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
670 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
672 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
673 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
675 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
677 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
683 // PAL5356: update VTK selection
684 ::UpdateVtkSelection();
687 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
688 bOk = bOk && it.data()->SetSettings( parent );
690 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
691 if (getenv( "GEOM_CLIPPING" ) == NULL)
693 QMenuItem* mi = Mb->findItem(50);
694 if (mi && mi->popup())
695 mi->popup()->removeItem(507);
702 //=======================================================================
703 // function : createGeomAction
705 //=======================================================================
706 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
709 QWidget* parent = application()->desktop();
710 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
712 if ( icon_id.length() )
713 pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
715 pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
717 icon = QIconSet( pix );
719 QString tooltip = tr( QString( "TOP_" )+po_id ),
720 menu = tr( QString( "MEN_" )+po_id ),
721 status_bar = tr( QString( "STB_" )+po_id );
723 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
728 //=======================================================================
729 // function : GeometryGUI::Deactivate()
730 // purpose : Called when GEOM module is deactivated [ static ]
731 //=======================================================================
732 void GeometryGUI::initialize( CAM_Application* app )
734 SalomeApp_Module::initialize( app );
736 // ----- create actions --------------
738 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
739 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
741 createGeomAction( 33, "DELETE" );
743 createGeomAction( 4011, "POINT" );
744 createGeomAction( 4012, "LINE" );
745 createGeomAction( 4013, "CIRCLE" );
746 createGeomAction( 4014, "ELLIPSE" );
747 createGeomAction( 4015, "ARC" );
748 createGeomAction( 4019, "CURVE" );
749 createGeomAction( 4016, "VECTOR" );
750 createGeomAction( 4017, "PLANE" );
751 createGeomAction( 4018, "WORK_PLANE" );
752 createGeomAction( 4020, "LOCAL_CS" );
754 createGeomAction( 4021, "BOX" );
755 createGeomAction( 4022, "CYLINDER" );
756 createGeomAction( 4023, "SPHERE" );
757 createGeomAction( 4024, "TORUS" );
758 createGeomAction( 4025, "CONE" );
760 createGeomAction( 4031, "EXTRUSION" );
761 createGeomAction( 4032, "REVOLUTION" );
762 createGeomAction( 4033, "FILLING" );
763 createGeomAction( 4034, "PIPE" );
765 createGeomAction( 800, "GROUP_CREATE" );
766 createGeomAction( 801, "GROUP_EDIT" );
768 createGeomAction( 9997, "Q_FACE" );
769 createGeomAction( 9999, "HEX_SOLID" );
771 createGeomAction( 404, "SKETCH" );
772 createGeomAction( 407, "EXPLODE" );
774 createGeomAction( 4081, "EDGE" );
775 createGeomAction( 4082, "WIRE" );
776 createGeomAction( 4083, "FACE" );
777 createGeomAction( 4084, "SHELL" );
778 createGeomAction( 4085, "SOLID" );
779 createGeomAction( 4086, "COMPOUND" );
781 createGeomAction( 5011, "FUSE" );
782 createGeomAction( 5012, "COMMON" );
783 createGeomAction( 5013, "CUT" );
784 createGeomAction( 5014, "SECTION" );
786 createGeomAction( 5021, "TRANSLATION" );
787 createGeomAction( 5022, "ROTATION" );
788 createGeomAction( 5023, "MODIFY_LOCATION" );
789 createGeomAction( 5024, "MIRROR" );
790 createGeomAction( 5025, "SCALE" );
791 createGeomAction( 5026, "OFFSET" );
792 createGeomAction( 5027, "MUL_TRANSLATION" );
793 createGeomAction( 5028, "MUL_ROTATION" );
795 createGeomAction( 503, "PARTITION" );
796 createGeomAction( 504, "ARCHIMEDE" );
797 createGeomAction( 505, "FILLET" );
798 createGeomAction( 506, "CHAMFER" );
799 //createGeomAction( 507, "CLIPPING" );
801 createGeomAction( 9998, "MUL_TRANSFORM" );
802 createGeomAction( 9995, "EXPLODE_BLOCKS" );
803 createGeomAction( 99991, "PROPAGATE" );
805 createGeomAction( 601, "SEWING" );
806 createGeomAction( 602, "GLUE_FACES" );
807 createGeomAction( 603, "SUPPRESS_FACES" );
808 createGeomAction( 604, "SUPPERSS_HOLES" );
809 createGeomAction( 605, "SHAPE_PROCESS" );
810 createGeomAction( 606, "CLOSE_CONTOUR" );
811 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
812 createGeomAction( 608, "POINT_ON_EDGE" );
813 createGeomAction( 609, "CHECK_FREE_BNDS" );
814 createGeomAction( 610, "CHECK_FREE_FACES" );
816 createGeomAction( 708, "POINT_COORDS" );
817 createGeomAction( 701, "BASIC_PROPS" );
818 createGeomAction( 702, "MASS_CENTER" );
819 createGeomAction( 703, "INERTIA" );
820 createGeomAction( 7041, "BND_BOX" );
821 createGeomAction( 7042, "MIN_DIST" );
823 createGeomAction( 705, "TOLERANCE" );
824 createGeomAction( 706, "WHAT_IS" );
825 createGeomAction( 707, "CHECK" );
826 createGeomAction( 7072, "CHECK_COMPOUND" );
828 createGeomAction( 5103, "CHECK_GEOMETRY" );
830 createGeomAction( 412, "SHADING_COLOR" );
831 createGeomAction( 413, "ISOS" );
832 createGeomAction( 414, "STEP_VALUE" );
834 createGeomAction( 211, "SHADING" );
835 createGeomAction( 212, "DISPLAY_ALL" );
836 createGeomAction( 214, "ERASE_ALL" );
837 createGeomAction( 216, "DISPLAY" );
838 createGeomAction( 213, "DISPLAY_ONLY" );
839 createGeomAction( 215, "ERASE" );
841 createGeomAction( 901, "POP_RENAME" );
842 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
843 createGeomAction( 80312, "POP_SHADING", "", 0, true );
844 createGeomAction( 8032, "POP_COLOR" );
845 createGeomAction( 8033, "POP_TRANSPARENCY" );
846 createGeomAction( 8034, "POP_ISOS" );
847 createGeomAction( 8001, "POP_CREATE_GROUP" );
849 // make wireframe-shading items to be exclusive (only one at a time is selected)
850 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
851 //dispModeGr->add( action( 80311 ) );
852 //dispModeGr->add( action( 80312 ) );
853 // ---- create menu --------------------------
855 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
856 createMenu( separator(), fileId, 10 );
857 createMenu( 111, fileId, 10 );
858 createMenu( 121, fileId, 10 );
859 createMenu( separator(), fileId, -1 );
861 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
862 createMenu( 33, editId, -1 );
864 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
866 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
867 createMenu( 4011, basicId, -1 );
868 createMenu( 4012, basicId, -1 );
869 createMenu( 4013, basicId, -1 );
870 createMenu( 4014, basicId, -1 );
871 createMenu( 4015, basicId, -1 );
872 createMenu( 4019, basicId, -1 );
873 createMenu( separator(), basicId, -1 );
874 createMenu( 4016, basicId, -1 );
875 createMenu( 4017, basicId, -1 );
876 createMenu( 4018, basicId, -1 );
877 createMenu( 4020, basicId, -1 );
879 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
880 createMenu( 4021, primId, -1 );
881 createMenu( 4022, primId, -1 );
882 createMenu( 4023, primId, -1 );
883 createMenu( 4024, primId, -1 );
884 createMenu( 4025, primId, -1 );
886 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
887 createMenu( 4031, genId, -1 );
888 createMenu( 4032, genId, -1 );
889 createMenu( 4033, genId, -1 );
890 createMenu( 4034, genId, -1 );
891 createMenu( separator(), newEntId, -1 );
893 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
894 createMenu( 800, groupId, -1 );
895 createMenu( 801, groupId, -1 );
896 createMenu( separator(), newEntId, -1 );
898 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
899 createMenu( 9997, blocksId, -1 );
900 createMenu( 9999, blocksId, -1 );
902 createMenu( separator(), newEntId, -1 );
903 createMenu( 404, newEntId, -1 );
904 createMenu( separator(), newEntId, -1 );
905 createMenu( 407, newEntId, -1 );
907 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
908 createMenu( 4081, buildId, -1 );
909 createMenu( 4082, buildId, -1 );
910 createMenu( 4083, buildId, -1 );
911 createMenu( 4084, buildId, -1 );
912 createMenu( 4085, buildId, -1 );
913 createMenu( 4086, buildId, -1 );
915 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
917 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
918 createMenu( 5011, boolId, -1 );
919 createMenu( 5012, boolId, -1 );
920 createMenu( 5013, boolId, -1 );
921 createMenu( 5014, boolId, -1 );
923 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
924 createMenu( 5021, transId, -1 );
925 createMenu( 5022, transId, -1 );
926 createMenu( 5023, transId, -1 );
927 createMenu( 5024, transId, -1 );
928 createMenu( 5025, transId, -1 );
929 createMenu( 5026, transId, -1 );
930 createMenu( separator(), transId, -1 );
931 createMenu( 5027, transId, -1 );
932 createMenu( 5028, transId, -1 );
934 createMenu( 503, operId, -1 );
935 createMenu( 504, operId, -1 );
936 createMenu( separator(), operId, -1 );
937 createMenu( 505, transId, -1 );
938 createMenu( 506, transId, -1 );
939 //createMenu( 507, transId, -1 );
941 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
942 createMenu( 9998, blockId, -1 );
943 createMenu( 9995, blockId, -1 );
944 createMenu( 99991, blockId, -1 );
946 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
947 createMenu( 605, repairId, -1 );
948 createMenu( 603, repairId, -1 );
949 createMenu( 606, repairId, -1 );
950 createMenu( 607, repairId, -1 );
951 createMenu( 604, repairId, -1 );
952 createMenu( 601, repairId, -1 );
953 createMenu( 602, repairId, -1 );
954 createMenu( 608, repairId, -1 );
955 createMenu( 609, repairId, -1 );
956 createMenu( 610, repairId, -1 );
958 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
959 createMenu( 708, measurId, -1 );
960 createMenu( 701, measurId, -1 );
961 createMenu( separator(), measurId, -1 );
962 createMenu( 702, measurId, -1 );
963 createMenu( 703, measurId, -1 );
964 createMenu( separator(), measurId, -1 );
966 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
967 createMenu( 7041, dimId, -1 );
968 createMenu( 7042, dimId, -1 );
969 createMenu( separator(), measurId, -1 );
971 createMenu( 705, measurId, -1 );
972 createMenu( separator(), measurId, -1 );
973 createMenu( 706, measurId, -1 );
974 createMenu( 707, measurId, -1 );
975 createMenu( 7072, measurId, -1 );
977 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
978 createMenu( separator(), toolsId, -1 );
979 createMenu( 5103, toolsId, -1 );
981 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
982 //createMenu( separator(), prefId, -1 );
983 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
984 //createMenu( 412, geomId, -1 );
985 //createMenu( 413, geomId, -1 );
986 //createMenu( 414, geomId, -1 );
987 //createMenu( separator(), prefId, -1 );
989 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
990 createMenu( separator(), viewId, -1 );
992 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
993 createMenu( 211, dispmodeId, -1 );
995 createMenu( separator(), viewId, -1 );
996 createMenu( 212, viewId, -1 );
997 createMenu( 214, viewId, -1 );
998 createMenu( separator(), viewId, -1 );
999 createMenu( 216, viewId, -1 );
1000 createMenu( 213, viewId, -1 );
1001 createMenu( 215, viewId, -1 );
1003 // ---- create toolbars --------------------------
1005 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1006 createTool( 4011, basicTbId );
1007 createTool( 4012, basicTbId );
1008 createTool( 4013, basicTbId );
1009 createTool( 4014, basicTbId );
1010 createTool( 4015, basicTbId );
1011 createTool( 4019, basicTbId );
1012 createTool( 4016, basicTbId );
1013 createTool( 4017, basicTbId );
1014 createTool( 4018, basicTbId );
1015 createTool( 4020, basicTbId );
1017 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1018 createTool( 4021, primTbId );
1019 createTool( 4022, primTbId );
1020 createTool( 4023, primTbId );
1021 createTool( 4024, primTbId );
1022 createTool( 4025, primTbId );
1024 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1025 createTool( 5011, boolTbId );
1026 createTool( 5012, boolTbId );
1027 createTool( 5013, boolTbId );
1028 createTool( 5014, boolTbId );
1030 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1031 createTool( 4031, genTbId );
1032 createTool( 4032, genTbId );
1033 createTool( 4033, genTbId );
1034 createTool( 4034, genTbId );
1036 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1037 createTool( 5021, transTbId );
1038 createTool( 5022, transTbId );
1039 createTool( 5023, transTbId );
1040 createTool( 5024, transTbId );
1041 createTool( 5025, transTbId );
1042 createTool( 5026, transTbId );
1043 createTool( separator(), transTbId );
1044 createTool( 5027, transTbId );
1045 createTool( 5028, transTbId );
1047 QtxPopupMgr* mgr = popupMgr();
1048 mgr->insert( action( 901 ), -1, -1 ); // rename
1049 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1050 mgr->insert( action( 8001 ), -1, -1 ); // create group
1051 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1052 mgr->insert( action( 801 ), -1, -1 ); // edit group
1053 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1054 mgr->insert( separator(), -1, -1 ); // -----------
1055 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1056 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1057 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1058 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Wireframe'", false );
1059 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1060 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1061 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Shading'", false );
1062 mgr->insert( separator(), -1, -1 ); // -----------
1063 mgr->insert( action( 8032 ), -1, -1 ); // color
1064 mgr->setRule( action( 8032 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1065 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1066 mgr->setRule( action( 8033 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
1067 mgr->insert( action( 8034 ), -1, -1 ); // isos
1068 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0", true );
1069 mgr->insert( separator(), -1, -1 ); // -----------
1070 mgr->insert( action( 216 ), -1, -1 ); // display
1071 mgr->setRule( action( 216 ), "(selcount>0) and (((isActiveView=true) and (($type in {'Shape' 'Group'} and (not isVisible)) or type='Component'))"
1072 "or ((isActiveView=false) and ($type in {'Shape' 'Group' 'Component'})))", true );
1073 mgr->insert( action( 215 ), -1, -1 ); // erase
1074 mgr->setRule( action( 215 ), "(isActiveView=true) and (($type in {'Shape' 'Group'} and isVisible and selcount>0) or (type='Component' and selcount=1))", true );
1075 mgr->insert( action( 214 ), -1, -1 ); // erase All
1076 mgr->setRule( action( 214 ), "client='OCCViewer' or client='VTKViewer'", true );
1077 mgr->insert( action( 213 ), -1, -1 ); // display only
1078 mgr->setRule( action( 213 ), "($type in {'Shape' 'Group'} and selcount>0) or (type='Component' and selcount=1)", true );
1079 mgr->insert( separator(), -1, -1 );
1082 //=======================================================================
1083 // function : GeometryGUI::Deactivate()
1084 // purpose : Called when GEOM module is deactivated [ static ]
1085 //=======================================================================
1086 bool GeometryGUI::activateModule( SUIT_Study* study )
1088 if ( CORBA::is_nil( myComponentGeom ) )
1091 bool res = SalomeApp_Module::activateModule( study );
1096 setMenuShown( true );
1097 setToolShown( true );
1099 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1100 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1101 connect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1102 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1104 GUIMap::Iterator it;
1105 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1106 it.data()->activate( application()->desktop() );
1108 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1109 SUIT_ViewManager* vm;
1110 ViewManagerList OCCViewManagers, VTKViewManagers;
1111 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1112 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1113 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1114 application()->viewManagers( VTKViewer_Viewer::Type(), VTKViewManagers );
1115 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1116 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1118 // disable OCC selectors
1119 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1120 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1121 sr->setEnabled(true);
1123 // disable VTK selectors
1124 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1125 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1126 sr->setEnabled(true);
1132 //=======================================================================
1133 // function : GeometryGUI::Deactivate()
1134 // purpose : Called when GEOM module is deactivated [ static ]
1135 //=======================================================================
1136 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1138 setMenuShown( false );
1139 setToolShown( false );
1141 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1142 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1143 disconnect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1144 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1146 EmitSignalCloseAllDialogs();
1148 GUIMap::Iterator it;
1149 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1150 it.data()->deactivate();
1152 myOCCSelectors.clear();
1153 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1155 myVTKSelectors.clear();
1156 getApp()->selectionMgr()->setEnabled( true, VTKViewer_Viewer::Type() );
1158 return SalomeApp_Module::deactivateModule( study );
1161 //=================================================================================
1162 // function : GeometryGUI::DefinePopup()
1163 // purpose : Called from desktop to define popup menu [static]
1164 //=================================================================================
1166 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1168 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1169 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1174 if ( theParent == "Viewer" ) {
1175 if ( Sel->IObjectCount() == 0 )
1176 theContext = "NothingSelected";
1179 if ( Sel->IObjectCount() == 1 ) {
1180 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1181 if( IO->hasEntry() ) {
1182 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1183 if ( !sobj->_is_nil() ) {
1184 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1185 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1186 // component is selected
1187 theObject = "Component";
1190 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1191 if ( !CORBA::is_nil( aGObj ) ) {
1192 switch( aGObj->GetType() ) {
1194 theObject = "Group";
1197 theObject = "Shape";
1207 //=================================================================================
1208 // function : GeometryGUI::CustomPopup()
1209 // purpose : Called from desktop to create popup menu [static]
1210 //=================================================================================
1211 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1212 const QString& theParent, const QString& theObject)
1214 GeometryGUI* geomGUI = GetGeomGUI();
1216 // Deactivate any non modal dialog box to get the neutral point
1217 geomGUI->EmitSignalDeactivateDialog();
1218 QAD_Study* anActiveStudy = parent->getActiveStudy();
1219 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1220 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1221 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1222 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1223 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1224 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1225 int aDisplayMode = 0;
1228 if ( aViewFrame->getTypeView() == VIEW_OCC )
1229 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1230 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1231 aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
1233 int nbSel = Sel->IObjectCount();
1236 ////// NOTHING SELECTED
1239 else if ( nbSel == 1 ) {
1240 ////// SINGLE OBJECT SELECTION
1241 if ( parentComponent != parent->getActiveComponent() ) {
1242 ////// selected object does not belong to GEOM module:
1243 // remove all commands except Display/Erase...
1245 int id = popup->idAt( 0 );
1246 if ( id <= QAD_TopLabel_Popup_ID )
1247 popup->removeItemAt( 0 );
1253 ////// selected object belong to the GEOM module
1254 // get interactive object
1255 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1256 objectName = IObject->getName();
1257 // if object has entry get SObject
1258 SALOMEDS::SObject_var SO;
1259 if ( IObject->hasEntry() )
1260 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1262 if ( theObject == "Component" ) {
1263 ////// menu for component
1264 if ( !isOCCViewer && !isVTKViewer ) {
1265 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1266 popup->removeItem( QAD_Display_Popup_ID );
1267 popup->removeItem( QAD_Erase_Popup_ID );
1271 ////// not component (should be shape)
1272 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1273 popup->removeItem( 804 ); // "Add in Study"
1275 // Here could be analysis of the geom shape's type
1278 SALOMEDS::GenericAttribute_var aTmpAttr;
1279 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1280 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1282 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1283 if ( theObject == "Shape" )
1284 popup->removeItem( 800 ); // Create Group
1285 else if ( theObject == "Group" )
1286 popup->removeItem( 801 ); // Edit Group
1289 if ( isOCCViewer || isVTKViewer ) {
1290 ////// current viewer is OCC or VTK
1291 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1292 if ( aViewFrame->isVisible( IObject ) ) {
1293 ////// object is already displayed in the viewer
1294 popup->removeItem( QAD_Display_Popup_ID );
1295 if ( isOCCViewer ) {
1296 ////// OCC viewer only
1297 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1298 if ( occPrs && !occPrs->IsNull() ) {
1299 AIS_ListOfInteractive ioList;
1300 occPrs->GetObjects( ioList );
1301 QMenuItem* mi = popup->findItem( 803 );
1302 if ( mi && mi->popup() ) {
1303 if ( ioList.First()->DisplayMode() == 0 )
1304 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1305 else if ( ioList.First()->DisplayMode() == 1 )
1306 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1307 else if ( ioList.First()->DisplayMode() < 0 )
1308 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1313 ////// VTK viewer only
1314 popup->removeItem( 8034 ); // "Isos"
1315 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
1316 if ( vtkPrs && !vtkPrs->IsNull() ) {
1317 vtkActorCollection* actorList = vtkPrs->GetObjects();
1318 actorList->InitTraversal();
1319 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1320 QMenuItem* mi = popup->findItem( 803 );
1321 if ( ac && mi && mi->popup() ) {
1322 if ( ac->getDisplayMode() == 0 )
1323 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1324 else if ( ac->getDisplayMode() == 1 )
1325 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1327 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1333 ////// object is not yet displayed in the viewer
1334 popup->removeItem( 803 ); // "Display Mode"
1335 popup->removeItem( 8032 ); // "Color"
1336 popup->removeItem( 8033 ); // "Transparency"
1337 popup->removeItem( 8034 ); // "Isos"
1338 popup->removeItem( QAD_Erase_Popup_ID );
1343 ////// other viewer type (neither OCC nor VTK)
1344 popup->removeItem( 803 ); // "Display Mode"
1345 popup->removeItem( 8032 ); // "Color"
1346 popup->removeItem( 8033 ); // "Transparency"
1347 popup->removeItem( 8034 ); // "Isos"
1348 popup->removeItem( QAD_Display_Popup_ID );
1349 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1350 popup->removeItem( QAD_Erase_Popup_ID );
1356 ////// MULTIPLE SELECTION
1357 if ( parentComponent != parent->getActiveComponent() ) {
1358 ////// not GEOM module objects or objects belong to different modules
1359 // remove all commands except Display/Erase...
1361 int id = popup->idAt( 0 );
1362 if ( id <= QAD_TopLabel_Popup_ID )
1363 popup->removeItemAt( 0 );
1367 if ( parentComponent.isNull() ) {
1368 ////// objects belong to different modules
1369 popup->removeItem(QAD_Display_Popup_ID);
1370 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1371 popup->removeItem(QAD_Erase_Popup_ID);
1374 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1378 ////// all selected objects belong to GEOM module
1379 popup->removeItem( 901 ); // "Rename"
1381 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1382 bool isComponent = false;
1383 bool needOpen = false;
1384 bool needDisplay = false;
1385 bool needErase = false;
1386 int needToPublish = 0;
1388 for( ;It.More();It.Next() ) {
1389 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1391 if ( aViewFrame->isVisible( anIObject ) )
1396 if( anIObject->hasEntry() ) {
1397 needToPublish = -1; /////// VSR : TO BE REMOVED
1398 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1399 SALOMEDS::GenericAttribute_var aTmpAttr;
1400 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1401 needOpen = true; /////// VSR : TO BE REMOVED
1402 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1406 if ( needToPublish != -1 ) needToPublish = 1;
1409 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1410 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1411 popup->removeItem( 803 ); // "Display Mode"
1412 popup->removeItem( 8032 ); // "Color"
1413 popup->removeItem( 8033 ); // "Transparency"
1414 popup->removeItem( 8034 ); // "Isos"
1415 popup->removeItem( 804 ); // "Add in Study"
1416 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1417 popup->removeItem( QAD_Display_Popup_ID );
1418 popup->removeItem( QAD_Erase_Popup_ID );
1421 popup->removeItem( 9024 ); // "Open"
1422 if ( needToPublish <= 0 )
1423 popup->removeItem( 804 ); // "Add in Study"
1426 popup->removeItem( 803 ); // "Display Mode"
1427 popup->removeItem( 8032 ); // "Color"
1428 popup->removeItem( 8033 ); // "Transparency"
1429 popup->removeItem( 8034 ); // "Isos"
1430 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1434 popup->removeItem( QAD_Display_Popup_ID );
1436 popup->removeItem( QAD_Erase_Popup_ID );
1438 popup->removeItem( 8034 ); // "Isos"
1443 // check popup for unnecessary separators
1444 QAD_Tools::checkPopup( popup );
1445 // find popup menu's TopLabel item (with title)
1446 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1447 if ( topItem >= 0 ) {
1448 // remove popup menu's title item
1449 popup->removeItem( QAD_TopLabel_Popup_ID );
1450 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1451 // set bold font for popup menu's title
1452 QFont f = popup->font(); f.setBold( TRUE );
1453 popup->removeItem( QAD_TopLabel_Popup_ID );
1454 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1463 //=======================================================================
1464 // function : GeometryGUI::BuildPresentation()
1466 //=======================================================================
1467 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1469 //GEOM_Displayer().Display( io, false, win );
1472 //=======================================================================
1473 // function : setCommandsEnabled()
1474 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1475 //=======================================================================
1476 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1481 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1482 // const bool ViewVTK = ( win->getViewManager()->getType() == VTKViewer_Viewer::Type() );
1484 // disable non-OCC viewframe menu commands
1485 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1486 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1487 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1488 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1489 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1490 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1491 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1492 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1494 action( 800 )->setEnabled( ViewOCC ); // Create Group
1495 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1497 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1500 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1502 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1503 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1506 void GeometryGUI::viewManagers( QStringList& lst ) const
1508 lst.append( OCCViewer_Viewer::Type() );
1511 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1513 if ( vm->getType() == OCCViewer_Viewer::Type() )
1515 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1516 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1518 // disable OCC selectors
1519 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1520 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1521 sr->setEnabled(true);
1523 else if ( vm->getType() == VTKViewer_Viewer::Type() )
1525 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1526 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1528 // disable VTK selectors
1529 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1530 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1531 sr->setEnabled(true);
1535 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1537 SUIT_ViewModel* viewer = vm->getViewModel();
1538 if ( vm->getType() == OCCViewer_Viewer::Type() )
1540 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1541 if ( sr->viewer() == viewer )
1543 myOCCSelectors.remove( sr );
1547 if ( vm->getType() == VTKViewer_Viewer::Type() )
1549 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1550 if ( sr->viewer() == viewer )
1552 myVTKSelectors.remove( sr );
1558 QString GeometryGUI::engineIOR() const
1560 if ( !CORBA::is_nil( GetGeomGen() ) )
1561 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1562 return QString( "" );
1565 SalomeApp_Selection* GeometryGUI::createSelection() const
1567 return new GEOMGUI_Selection();
1570 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1572 SalomeApp_Module::contextMenuPopup( client, menu, title );
1574 getApp()->selectionMgr()->selectedObjects( lst );
1575 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1576 Handle(SALOME_InteractiveObject) io = lst.First();
1577 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1578 _PTR(Study) study = appStudy->studyDS();
1579 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1581 title = QString( obj->GetName().c_str() );
1585 void GeometryGUI::createPreferences()
1587 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1589 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1590 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1591 SalomeApp_Preferences::Color, "Geometry", "shading_color" );
1592 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1593 SalomeApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1594 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1595 SalomeApp_Preferences::Selector, "Geometry", "display_mode" );
1597 setPreferenceProperty( genGroup, "columns", 1 );
1599 setPreferenceProperty( step, "min", 0.001 );
1600 setPreferenceProperty( step, "max", 10000 );
1601 setPreferenceProperty( step, "precision", 3 );
1603 // Set property for default display mode
1604 QStringList aModesList;
1605 aModesList.append( tr("MEN_WIREFRAME") );
1606 aModesList.append( tr("MEN_SHADING") );
1608 QValueList<QVariant> anIndexesList;
1609 anIndexesList.append(0);
1610 anIndexesList.append(1);
1612 setPreferenceProperty( dispmode, "strings", aModesList );
1613 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1616 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1620 SalomeApp_Displayer* GeometryGUI::displayer()
1623 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );