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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 <SVTK_ViewWindow.h>
45 #include <SVTK_RenderWindowInteractor.h>
46 #include <SVTK_InteractorStyle.h>
47 #include <SVTK_ViewModel.h>
48 #include <SVTK_ViewManager.h>
50 #include <SalomeApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <LightApp_VTKSelector.h>
53 #include <SalomeApp_Study.h>
54 #include <LightApp_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 <Aspect_TypeOfMarker.hxx>
65 #include <OSD_SharedLibrary.hxx>
67 #include <utilities.h>
69 #include <vtkCamera.h>
70 #include <vtkRenderer.h>
74 Standard_EXPORT CAM_Module* createModule() {
75 return new GeometryGUI();
81 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
83 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
85 // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
86 if (CORBA::is_nil(myComponentGeom))
88 return GeometryGUI::myComponentGeom;
91 bool GeometryGUI::InitGeomGen()
94 if( CORBA::is_nil( myComponentGeom ) ) return false;
98 //=======================================================================
99 // function : ClientSObjectToObject
101 //=======================================================================
102 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
104 _PTR(GenericAttribute) anAttr;
105 CORBA::Object_var anObj;
107 std::string aValue = theSObject->GetIOR();
108 if (strcmp(aValue.c_str(), "") != 0) {
109 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
110 anObj = anORB->string_to_object(aValue.c_str());
113 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
115 return anObj._retn();
118 //=======================================================================
119 // function : ClientStudyToStudy
121 //=======================================================================
122 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
124 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
125 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
126 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
127 int aStudyID = theStudy->StudyId();
128 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
129 return aDSStudy._retn();
132 //=================================================================================
133 // class : CustomItem
134 // purpose : Set Font to a text.
135 //=================================================================================
136 class CustomItem : public QCustomMenuItem
139 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
142 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
145 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
146 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
147 p->setFont( myFont );
148 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
154 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
157 bool fullSpan() const
167 //=======================================================================
168 // function : GeometryGUI::GeometryGUI()
169 // purpose : Constructor
170 //=======================================================================
171 GeometryGUI::GeometryGUI() :
172 SalomeApp_Module( "GEOM" )
174 if ( CORBA::is_nil( myComponentGeom ) )
176 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
177 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
178 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
182 myActiveDialogBox = 0;
185 gp_Pnt origin = gp_Pnt(0., 0., 0.);
186 gp_Dir direction = gp_Dir(0., 0., 1.);
187 myWorkingPlane = gp_Ax3(origin, direction);
189 myOCCSelectors.setAutoDelete( true );
190 myVTKSelectors.setAutoDelete( true );
195 //=======================================================================
196 // function : GeometryGUI::~GeometryGUI()
197 // purpose : Destructor
198 //=======================================================================
199 GeometryGUI::~GeometryGUI()
203 //=======================================================================
204 // function : GeometryGUI::getLibrary()
205 // purpose : get or load GUI library by name [ internal ]
206 //=======================================================================
207 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
208 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
210 if ( !myGUIMap.contains( libraryName ) ) {
211 // try to load library if it is not loaded yet
214 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
215 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
217 if( ( libs = getenv( "PATH" ) ) ) {
218 QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries
220 for( int i = dirList.count()-1; i >= 0; i-- ) {
221 QString dir = dirList[ i ];
222 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
224 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
225 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
227 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
228 continue; // continue search further
230 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
231 if ( osdF != NULL ) {
232 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
233 GEOMGUI* libGUI = (*func)(this);
235 myGUIMap[ libraryName ] = libGUI;
236 break; // found and loaded!
243 if ( myGUIMap.contains( libraryName ) )
244 // library is successfully loaded
245 return myGUIMap[ libraryName ];
249 //=======================================================================
250 // function : GeometryGUI::ActiveWorkingPlane()
251 // purpose : Activate Working Plane View
252 //=======================================================================
253 void GeometryGUI::ActiveWorkingPlane()
255 gp_Dir DZ = myWorkingPlane.Direction();
256 gp_Dir DY = myWorkingPlane.YDirection();
258 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
259 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
260 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
263 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
265 Handle(V3d_View) view3d = vw->getViewPort()->getView();
267 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
268 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
274 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
276 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
278 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
279 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
280 camera->SetFocalPoint(0,0,0);
287 //=======================================================================
288 // function : GeometryGUI::SetActiveDialogBox()
289 // purpose : Set active dialog box
290 //=======================================================================
291 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
293 myActiveDialogBox = (QDialog*)aDlg;
296 //=======================================================================
297 // function : GeometryGUI::EmitSignalDeactivateDialog()
298 // purpose : Emit a signal to deactivate the active dialog Box
299 //=======================================================================
300 void GeometryGUI::EmitSignalDeactivateDialog()
302 emit SignalDeactivateActiveDialog();
305 //=======================================================================
306 // function : GeometryGUI::EmitSignalCloseAllDialogs()
307 // purpose : Emit a signal to close all non modal dialogs box
308 //=======================================================================
309 void GeometryGUI::EmitSignalCloseAllDialogs()
311 emit SignalCloseAllDialogs();
314 //=======================================================================
315 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
316 // purpose : Emit a signal to inform that default real spin box step has
318 //=======================================================================
319 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
321 emit SignalDefaultStepValueChanged(newVal);
324 //=======================================================================
325 // function : GeometryGUI::OnGUIEvent()
326 // purpose : common slot for all menu/toolbar actions
327 //=======================================================================
328 void GeometryGUI::OnGUIEvent()
330 const QObject* obj = sender();
331 if ( !obj || !obj->inherits( "QAction" ) )
333 int id = actionId((QAction*)obj);
338 //=======================================================================
339 // function : GeometryGUI::OnGUIEvent()
340 // purpose : manage all events on GUI [static]
341 //=======================================================================
342 void GeometryGUI::OnGUIEvent( int id )
344 SUIT_Application* anApp = application();
346 SUIT_Desktop* desk = anApp->desktop();
348 // check type of the active viewframe
349 SUIT_ViewWindow* window = desk->activeWindow();
350 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
351 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
352 // if current viewframe is not of OCC and not of VTK type - return immediately
353 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
354 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
355 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
358 // fix for IPAL9103, point 2
359 if ( CORBA::is_nil( GetGeomGen() ) ) {
360 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
364 GEOMGUI* library = 0;
365 // try to get-or-load corresponding GUI library
366 if( id == 111 || // MENU FILE - IMPORT BREP
367 id == 112 || // MENU FILE - IMPORT IGES
368 id == 113 || // MENU FILE - IMPORT STEP
369 id == 121 || // MENU FILE - EXPORT BREP
370 id == 122 || // MENU FILE - EXPORT IGES
371 id == 123 || // MENU FILE - EXPORT STEP
372 id == 31 || // MENU EDIT - COPY
373 id == 33 || // MENU EDIT - DELETE
374 id == 411 || // MENU SETTINGS - ADD IN STUDY
375 id == 412 || // MENU SETTINGS - SHADING COLOR
376 id == 413 || // MENU SETTINGS - ISOS
377 id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
378 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
379 id == 8032 || // POPUP VIEWER - COLOR
380 id == 8033 || // POPUP VIEWER - TRANSPARENCY
381 id == 8034 || // POPUP VIEWER - ISOS
382 id == 804 || // POPUP VIEWER - ADD IN STUDY
383 id == 901 || // OBJECT BROWSER - RENAME
384 id == 9024 ) { // OBJECT BROWSER - OPEN
385 //cout << "id " << id << " received" << endl;
387 library = getLibrary( "libGEOMToolsGUI.so" );
389 library = getLibrary( "GEOMToolsGUI.dll" );
392 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
393 id == 212 || // MENU VIEW - DISPLAY ALL
394 id == 213 || // MENU VIEW - DISPLAY ONLY
395 id == 214 || // MENU VIEW - ERASE ALL
396 id == 215 || // MENU VIEW - ERASE
397 id == 216 || // MENU VIEW - DISPLAY
398 id == 80311 || // POPUP VIEWER - WIREFRAME
399 id == 80312 ) { // POPUP VIEWER - SHADING
401 library = getLibrary( "libDisplayGUI.so" );
403 library = getLibrary( "DisplayGUI.dll" );
406 else if( id == 4011 || // MENU BASIC - POINT
407 id == 4012 || // MENU BASIC - LINE
408 id == 4013 || // MENU BASIC - CIRCLE
409 id == 4014 || // MENU BASIC - ELLIPSE
410 id == 4015 || // MENU BASIC - ARC
411 id == 4016 || // MENU BASIC - VECTOR
412 id == 4017 || // MENU BASIC - PLANE
413 id == 4018 || // MENU BASIC - WPLANE
414 id == 4019 || // MENU BASIC - CURVE
415 id == 4020 ) { // MENU BASIC - REPAIR
417 library = getLibrary( "libBasicGUI.so" );
419 library = getLibrary( "BasicGUI.dll" );
422 else if( id == 4021 || // MENU PRIMITIVE - BOX
423 id == 4022 || // MENU PRIMITIVE - CYLINDER
424 id == 4023 || // MENU PRIMITIVE - SPHERE
425 id == 4024 || // MENU PRIMITIVE - TORUS
426 id == 4025 ) { // MENU PRIMITIVE - CONE
428 library = getLibrary( "libPrimitiveGUI.so" );
430 library = getLibrary( "PrimitiveGUI.dll" );
433 else if( id == 4031 || // MENU GENERATION - PRISM
434 id == 4032 || // MENU GENERATION - REVOLUTION
435 id == 4033 || // MENU GENERATION - FILLING
436 id == 4034 ) { // MENU GENERATION - PIPE
438 library = getLibrary( "libGenerationGUI.so" );
440 library = getLibrary( "GenerationGUI.dll" );
443 else if( id == 404 || // MENU ENTITY - SKETCHER
444 id == 407 ) { // MENU ENTITY - EXPLODE
446 library = getLibrary( "libEntityGUI.so" );
448 library = getLibrary( "EntityGUI.dll" );
451 else if( id == 4081 || // MENU BUILD - EDGE
452 id == 4082 || // MENU BUILD - WIRE
453 id == 4083 || // MENU BUILD - FACE
454 id == 4084 || // MENU BUILD - SHELL
455 id == 4085 || // MENU BUILD - SOLID
456 id == 4086 ) { // MENU BUILD - COMPUND
458 library = getLibrary( "libBuildGUI.so" );
460 library = getLibrary( "BuildGUI.dll" );
463 else if( id == 5011 || // MENU BOOLEAN - FUSE
464 id == 5012 || // MENU BOOLEAN - COMMON
465 id == 5013 || // MENU BOOLEAN - CUT
466 id == 5014 ) { // MENU BOOLEAN - SECTION
468 library = getLibrary( "libBooleanGUI.so" );
470 library = getLibrary( "BooleanGUI.dll" );
473 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
474 id == 5022 || // MENU TRANSFORMATION - ROTATION
475 id == 5023 || // MENU TRANSFORMATION - LOCATION
476 id == 5024 || // MENU TRANSFORMATION - MIRROR
477 id == 5025 || // MENU TRANSFORMATION - SCALE
478 id == 5026 || // MENU TRANSFORMATION - OFFSET
479 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
480 id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
482 library = getLibrary( "libTransformationGUI.so" );
484 library = getLibrary( "TransformationGUI.dll" );
487 else if( id == 503 || // MENU OPERATION - PARTITION
488 id == 504 || // MENU OPERATION - ARCHIMEDE
489 id == 505 || // MENU OPERATION - FILLET
490 id == 506 || // MENU OPERATION - CHAMFER
491 id == 507 ) { // MENU OPERATION - CLIPPING RANGE
493 library = getLibrary( "libOperationGUI.so" );
495 library = getLibrary( "OperationGUI.dll" );
498 else if( id == 601 || // MENU REPAIR - SEWING
499 id == 603 || // MENU REPAIR - SUPPRESS FACES
500 id == 604 || // MENU REPAIR - SUPPRESS HOLE
501 id == 605 || // MENU REPAIR - SHAPE PROCESSING
502 id == 606 || // MENU REPAIR - CLOSE CONTOUR
503 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
504 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
505 id == 609 || // MENU REPAIR - FREE BOUNDARIES
506 id == 610 || // MENU REPAIR - FREE FACES
507 id == 611 || // MENU REPAIR - CHANGE ORIENTATION
508 id == 602 ) { // MENU REPAIR - GLUE FACES
510 library = getLibrary( "libRepairGUI.so" );
512 library = getLibrary( "RepairGUI.dll" );
515 else if( id == 701 || // MENU MEASURE - PROPERTIES
516 id == 702 || // MENU MEASURE - CDG
517 id == 703 || // MENU MEASURE - INERTIA
518 id == 7041 || // MENU MEASURE - BOUNDING BOX
519 id == 7042 || // MENU MEASURE - MIN DISTANCE
520 id == 705 || // MENU MEASURE - TOLERANCE
521 id == 706 || // MENU MEASURE - WHATIS
522 id == 707 || // MENU MEASURE - CHECK
523 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
524 id == 708 ) { // MENU MEASURE - POINT COORDINATES
526 library = getLibrary( "libMeasureGUI.so" );
528 library = getLibrary( "MeasureGUI.dll" );
531 else if( id == 800 || // MENU GROUP - CREATE
532 id == 8001 || // POPUP MENU - CREATE GROUP
533 id == 801 ) { // MENU GROUP - EDIT
535 library = getLibrary( "libGroupGUI.so" );
537 library = getLibrary( "GroupGUI.dll" );
540 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
541 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
542 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
543 id == 99991 || // MENU BLOCKS - PROPAGATE
544 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
546 library = getLibrary( "libBlocksGUI.so" );
548 library = getLibrary( "BlocksGUI.dll" );
552 // call method of corresponding GUI library
554 library->OnGUIEvent( id, desk );
556 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
560 //=================================================================================
561 // function : GeometryGUI::OnKeyPress()
562 // purpose : Called when any key is pressed by user [static]
563 //=================================================================================
564 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
568 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
569 SUIT_Application* anApp = application();
571 bOk = bOk && it.data()->OnKeyPress( pe, anApp->desktop(), win );
577 //=================================================================================
578 // function : GeometryGUI::OnMouseMove()
579 // purpose : Manages mouse move events [static]
580 //=================================================================================
581 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
585 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
586 SUIT_Application* anApp = application();
588 bOk = bOk && it.data()->OnMouseMove( pe, anApp->desktop(), win );
594 //=================================================================================
595 // function : GeometryGUI::0nMousePress()
596 // purpose : Manage mouse press events [static]
597 //=================================================================================
598 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
601 // OnMousePress() should return false if this event should be processed further
602 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
603 bool processed = false;
604 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
605 SUIT_Application* anApp = application();
607 processed = processed || it.data()->OnMousePress( pe, anApp->desktop(), win );
613 static void UpdateVtkSelection()
615 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
616 SUIT_ViewWindow* win = 0;
617 for ( win = winList.first(); win; win = winList.next() ) {
618 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
619 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
621 SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
622 anInteractor->SetSelectionProp();
623 anInteractor->SetSelectionTolerance();
624 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
626 aStyle->setPreselectionProp();
633 //=================================================================================
634 // function : GeometryGUI::SetSettings()
635 // purpose : Called when GEOM module is activated [static]
636 //=================================================================================
637 bool GeometryGUI::SetSettings()
639 QMenuBar* Mb = parent->getMainMenuBar();
640 SUIT_Study* ActiveStudy = application()->activeStudy();
642 // Wireframe or Shading
644 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
645 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
646 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
648 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
650 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
651 DisplayMode = ic->DisplayMode();
654 else if ( ViewVTK ) {
655 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
657 SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
658 DisplayMode = myRenderInter->GetDisplayMode();
662 if( DisplayMode == 1 )
664 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
666 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
669 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
670 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
671 int Settings_AddInStudy;
672 // if(!AddInStudy.isEmpty())
673 // Settings_AddInStudy = AddInStudy.toInt();
676 Settings_AddInStudy = 1;
677 Mb->setItemChecked(411, Settings_AddInStudy);
680 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
682 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
685 int count = ActiveStudy->getStudyFramesCount();
686 for(int i = 0; i < count; i++) {
687 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
688 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
689 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
691 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
692 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
694 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
696 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
702 // PAL5356: update VTK selection
703 ::UpdateVtkSelection();
706 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
707 bOk = bOk && it.data()->SetSettings( parent );
709 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
710 if (getenv( "GEOM_CLIPPING" ) == NULL)
712 QMenuItem* mi = Mb->findItem(50);
713 if (mi && mi->popup())
714 mi->popup()->removeItem(507);
721 //=======================================================================
722 // function : createGeomAction
724 //=======================================================================
725 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
728 QWidget* parent = application()->desktop();
729 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
731 if ( icon_id.length() )
732 pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
734 pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
736 icon = QIconSet( pix );
738 QString tooltip = tr( QString( "TOP_" )+po_id ),
739 menu = tr( QString( "MEN_" )+po_id ),
740 status_bar = tr( QString( "STB_" )+po_id );
742 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
747 //=======================================================================
748 // function : GeometryGUI::initialize()
749 // purpose : Called when GEOM module is created
750 //=======================================================================
751 void GeometryGUI::initialize( CAM_Application* app )
753 SalomeApp_Module::initialize( app );
755 // ----- create actions --------------
757 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
758 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
760 createGeomAction( 33, "DELETE" );
762 createGeomAction( 4011, "POINT" );
763 createGeomAction( 4012, "LINE" );
764 createGeomAction( 4013, "CIRCLE" );
765 createGeomAction( 4014, "ELLIPSE" );
766 createGeomAction( 4015, "ARC" );
767 createGeomAction( 4019, "CURVE" );
768 createGeomAction( 4016, "VECTOR" );
769 createGeomAction( 4017, "PLANE" );
770 createGeomAction( 4018, "WORK_PLANE" );
771 createGeomAction( 4020, "LOCAL_CS" );
773 createGeomAction( 4021, "BOX" );
774 createGeomAction( 4022, "CYLINDER" );
775 createGeomAction( 4023, "SPHERE" );
776 createGeomAction( 4024, "TORUS" );
777 createGeomAction( 4025, "CONE" );
779 createGeomAction( 4031, "EXTRUSION" );
780 createGeomAction( 4032, "REVOLUTION" );
781 createGeomAction( 4033, "FILLING" );
782 createGeomAction( 4034, "PIPE" );
784 createGeomAction( 800, "GROUP_CREATE" );
785 createGeomAction( 801, "GROUP_EDIT" );
787 createGeomAction( 9997, "Q_FACE" );
788 createGeomAction( 9999, "HEX_SOLID" );
790 createGeomAction( 404, "SKETCH" );
791 createGeomAction( 407, "EXPLODE" );
793 createGeomAction( 4081, "EDGE" );
794 createGeomAction( 4082, "WIRE" );
795 createGeomAction( 4083, "FACE" );
796 createGeomAction( 4084, "SHELL" );
797 createGeomAction( 4085, "SOLID" );
798 createGeomAction( 4086, "COMPOUND" );
800 createGeomAction( 5011, "FUSE" );
801 createGeomAction( 5012, "COMMON" );
802 createGeomAction( 5013, "CUT" );
803 createGeomAction( 5014, "SECTION" );
805 createGeomAction( 5021, "TRANSLATION" );
806 createGeomAction( 5022, "ROTATION" );
807 createGeomAction( 5023, "MODIFY_LOCATION" );
808 createGeomAction( 5024, "MIRROR" );
809 createGeomAction( 5025, "SCALE" );
810 createGeomAction( 5026, "OFFSET" );
811 createGeomAction( 5027, "MUL_TRANSLATION" );
812 createGeomAction( 5028, "MUL_ROTATION" );
814 createGeomAction( 503, "PARTITION" );
815 createGeomAction( 504, "ARCHIMEDE" );
816 createGeomAction( 505, "FILLET" );
817 createGeomAction( 506, "CHAMFER" );
818 //createGeomAction( 507, "CLIPPING" );
820 createGeomAction( 9998, "MUL_TRANSFORM" );
821 createGeomAction( 9995, "EXPLODE_BLOCKS" );
822 createGeomAction( 99991, "PROPAGATE" );
824 createGeomAction( 601, "SEWING" );
825 createGeomAction( 602, "GLUE_FACES" );
826 createGeomAction( 603, "SUPPRESS_FACES" );
827 createGeomAction( 604, "SUPPERSS_HOLES" );
828 createGeomAction( 605, "SHAPE_PROCESS" );
829 createGeomAction( 606, "CLOSE_CONTOUR" );
830 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
831 createGeomAction( 608, "POINT_ON_EDGE" );
832 createGeomAction( 609, "CHECK_FREE_BNDS" );
833 createGeomAction( 610, "CHECK_FREE_FACES" );
834 createGeomAction( 611, "CHANGE_ORIENTATION" );
836 createGeomAction( 708, "POINT_COORDS" );
837 createGeomAction( 701, "BASIC_PROPS" );
838 createGeomAction( 702, "MASS_CENTER" );
839 createGeomAction( 703, "INERTIA" );
840 createGeomAction( 7041, "BND_BOX" );
841 createGeomAction( 7042, "MIN_DIST" );
843 createGeomAction( 705, "TOLERANCE" );
844 createGeomAction( 706, "WHAT_IS" );
845 createGeomAction( 707, "CHECK" );
846 createGeomAction( 7072, "CHECK_COMPOUND" );
848 createGeomAction( 5103, "CHECK_GEOMETRY" );
850 createGeomAction( 412, "SHADING_COLOR" );
851 createGeomAction( 413, "ISOS" );
852 createGeomAction( 414, "STEP_VALUE" );
854 createGeomAction( 211, "SHADING" );
855 createGeomAction( 212, "DISPLAY_ALL" );
856 createGeomAction( 214, "ERASE_ALL" );
857 createGeomAction( 216, "DISPLAY" );
858 createGeomAction( 213, "DISPLAY_ONLY" );
859 createGeomAction( 215, "ERASE" );
861 createGeomAction( 901, "POP_RENAME" );
862 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
863 createGeomAction( 80312, "POP_SHADING", "", 0, true );
864 createGeomAction( 8032, "POP_COLOR" );
865 createGeomAction( 8033, "POP_TRANSPARENCY" );
866 createGeomAction( 8034, "POP_ISOS" );
867 createGeomAction( 8001, "POP_CREATE_GROUP" );
869 // make wireframe-shading items to be exclusive (only one at a time is selected)
870 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
871 //dispModeGr->add( action( 80311 ) );
872 //dispModeGr->add( action( 80312 ) );
873 // ---- create menu --------------------------
875 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
876 createMenu( separator(), fileId, 10 );
877 createMenu( 111, fileId, 10 );
878 createMenu( 121, fileId, 10 );
879 createMenu( separator(), fileId, -1 );
881 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
882 createMenu( 33, editId, -1 );
884 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
886 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
887 createMenu( 4011, basicId, -1 );
888 createMenu( 4012, basicId, -1 );
889 createMenu( 4013, basicId, -1 );
890 createMenu( 4014, basicId, -1 );
891 createMenu( 4015, basicId, -1 );
892 createMenu( 4019, basicId, -1 );
893 createMenu( separator(), basicId, -1 );
894 createMenu( 4016, basicId, -1 );
895 createMenu( 4017, basicId, -1 );
896 createMenu( 4018, basicId, -1 );
897 createMenu( 4020, basicId, -1 );
899 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
900 createMenu( 4021, primId, -1 );
901 createMenu( 4022, primId, -1 );
902 createMenu( 4023, primId, -1 );
903 createMenu( 4024, primId, -1 );
904 createMenu( 4025, primId, -1 );
906 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
907 createMenu( 4031, genId, -1 );
908 createMenu( 4032, genId, -1 );
909 createMenu( 4033, genId, -1 );
910 createMenu( 4034, genId, -1 );
911 createMenu( separator(), newEntId, -1 );
913 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
914 createMenu( 800, groupId, -1 );
915 createMenu( 801, groupId, -1 );
916 createMenu( separator(), newEntId, -1 );
918 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
919 createMenu( 9997, blocksId, -1 );
920 createMenu( 9999, blocksId, -1 );
922 createMenu( separator(), newEntId, -1 );
923 createMenu( 404, newEntId, -1 );
924 createMenu( separator(), newEntId, -1 );
925 createMenu( 407, newEntId, -1 );
927 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
928 createMenu( 4081, buildId, -1 );
929 createMenu( 4082, buildId, -1 );
930 createMenu( 4083, buildId, -1 );
931 createMenu( 4084, buildId, -1 );
932 createMenu( 4085, buildId, -1 );
933 createMenu( 4086, buildId, -1 );
935 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
937 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
938 createMenu( 5011, boolId, -1 );
939 createMenu( 5012, boolId, -1 );
940 createMenu( 5013, boolId, -1 );
941 createMenu( 5014, boolId, -1 );
943 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
944 createMenu( 5021, transId, -1 );
945 createMenu( 5022, transId, -1 );
946 createMenu( 5023, transId, -1 );
947 createMenu( 5024, transId, -1 );
948 createMenu( 5025, transId, -1 );
949 createMenu( 5026, transId, -1 );
950 createMenu( separator(), transId, -1 );
951 createMenu( 5027, transId, -1 );
952 createMenu( 5028, transId, -1 );
954 createMenu( 503, operId, -1 );
955 createMenu( 504, operId, -1 );
956 createMenu( separator(), operId, -1 );
957 createMenu( 505, transId, -1 );
958 createMenu( 506, transId, -1 );
959 //createMenu( 507, transId, -1 );
961 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
962 createMenu( 9998, blockId, -1 );
963 createMenu( 9995, blockId, -1 );
964 createMenu( 99991, blockId, -1 );
966 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
967 createMenu( 605, repairId, -1 );
968 createMenu( 603, repairId, -1 );
969 createMenu( 606, repairId, -1 );
970 createMenu( 607, repairId, -1 );
971 createMenu( 604, repairId, -1 );
972 createMenu( 601, repairId, -1 );
973 createMenu( 602, repairId, -1 );
974 createMenu( 608, repairId, -1 );
975 createMenu( 609, repairId, -1 );
976 createMenu( 610, repairId, -1 );
977 createMenu( 611, repairId, -1 );
979 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
980 createMenu( 708, measurId, -1 );
981 createMenu( 701, measurId, -1 );
982 createMenu( separator(), measurId, -1 );
983 createMenu( 702, measurId, -1 );
984 createMenu( 703, measurId, -1 );
985 createMenu( separator(), measurId, -1 );
987 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
988 createMenu( 7041, dimId, -1 );
989 createMenu( 7042, dimId, -1 );
990 createMenu( separator(), measurId, -1 );
992 createMenu( 705, measurId, -1 );
993 createMenu( separator(), measurId, -1 );
994 createMenu( 706, measurId, -1 );
995 createMenu( 707, measurId, -1 );
996 createMenu( 7072, measurId, -1 );
998 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
999 createMenu( separator(), toolsId, -1 );
1000 createMenu( 5103, toolsId, -1 );
1002 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
1003 //createMenu( separator(), prefId, -1 );
1004 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
1005 //createMenu( 412, geomId, -1 );
1006 //createMenu( 413, geomId, -1 );
1007 //createMenu( 414, geomId, -1 );
1008 //createMenu( separator(), prefId, -1 );
1010 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1011 createMenu( separator(), viewId, -1 );
1013 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1014 createMenu( 211, dispmodeId, -1 );
1016 createMenu( separator(), viewId, -1 );
1017 createMenu( 212, viewId, -1 );
1018 createMenu( 214, viewId, -1 );
1019 createMenu( separator(), viewId, -1 );
1023 because of these items are accessible through object browser and viewers
1024 we have removed they from main menu
1026 createMenu( 216, viewId, -1 );
1027 createMenu( 213, viewId, -1 );
1028 createMenu( 215, viewId, -1 );
1031 // ---- create toolbars --------------------------
1033 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1034 createTool( 4011, basicTbId );
1035 createTool( 4012, basicTbId );
1036 createTool( 4013, basicTbId );
1037 createTool( 4014, basicTbId );
1038 createTool( 4015, basicTbId );
1039 createTool( 4019, basicTbId );
1040 createTool( 4016, basicTbId );
1041 createTool( 4017, basicTbId );
1042 createTool( 4018, basicTbId );
1043 createTool( 4020, basicTbId );
1045 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1046 createTool( 4021, primTbId );
1047 createTool( 4022, primTbId );
1048 createTool( 4023, primTbId );
1049 createTool( 4024, primTbId );
1050 createTool( 4025, primTbId );
1052 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1053 createTool( 5011, boolTbId );
1054 createTool( 5012, boolTbId );
1055 createTool( 5013, boolTbId );
1056 createTool( 5014, boolTbId );
1058 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1059 createTool( 4031, genTbId );
1060 createTool( 4032, genTbId );
1061 createTool( 4033, genTbId );
1062 createTool( 4034, genTbId );
1064 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1065 createTool( 5021, transTbId );
1066 createTool( 5022, transTbId );
1067 createTool( 5023, transTbId );
1068 createTool( 5024, transTbId );
1069 createTool( 5025, transTbId );
1070 createTool( 5026, transTbId );
1071 createTool( separator(), transTbId );
1072 createTool( 5027, transTbId );
1073 createTool( 5028, transTbId );
1075 // ---- create popup menus --------------------------
1077 QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1078 QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1080 QtxPopupMgr* mgr = popupMgr();
1081 mgr->insert( action( 901 ), -1, -1 ); // rename
1082 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1083 mgr->insert( action( 8001 ), -1, -1 ); // create group
1084 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1085 mgr->insert( action( 801 ), -1, -1 ); // edit group
1086 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1087 mgr->insert( separator(), -1, -1 ); // -----------
1088 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1089 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1090 mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, true );
1091 mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", false );
1092 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1093 mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, true );
1094 mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", false );
1095 mgr->insert( separator(), -1, -1 ); // -----------
1096 mgr->insert( action( 8032 ), -1, -1 ); // color
1097 mgr->setRule( action( 8032 ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", true );
1098 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1099 mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, true );
1100 mgr->insert( action( 8034 ), -1, -1 ); // isos
1101 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true );
1102 mgr->insert( separator(), -1, -1 ); // -----------
1105 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1106 onlyComponent = "((type='Component') and selcount=1)",
1107 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1108 types = "'Shape' 'Group'";
1110 mgr->insert( action( 216 ), -1, -1 ); // display
1111 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), true );
1113 mgr->insert( action( 215 ), -1, -1 ); // erase
1114 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), true );
1116 mgr->insert( action( 214 ), -1, -1 ); // erase All
1117 mgr->setRule( action( 214 ), clientOCCorVTK, true );
1119 mgr->insert( action( 213 ), -1, -1 ); // display only
1120 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), true );
1121 mgr->insert( separator(), -1, -1 );
1123 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1126 //=======================================================================
1127 // function : GeometryGUI::activateModule()
1128 // purpose : Called when GEOM module is activated
1129 //=======================================================================
1130 bool GeometryGUI::activateModule( SUIT_Study* study )
1132 if ( CORBA::is_nil( myComponentGeom ) )
1135 bool res = SalomeApp_Module::activateModule( study );
1140 setMenuShown( true );
1141 setToolShown( true );
1143 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1144 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1146 // Reset actions accelerator keys
1147 //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1148 //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1149 action(111)->setEnabled(true); // Import
1150 action(121)->setEnabled(true); // Export
1152 GUIMap::Iterator it;
1153 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1154 it.data()->activate( application()->desktop() );
1156 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1157 SUIT_ViewManager* vm;
1158 ViewManagerList OCCViewManagers, VTKViewManagers;
1159 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1160 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1161 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1162 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1163 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1164 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1166 // disable OCC selectors
1167 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1168 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1169 sr->setEnabled(true);
1171 // disable VTK selectors
1172 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1173 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1174 sr->setEnabled(true);
1180 //=======================================================================
1181 // function : GeometryGUI::deactivateModule()
1182 // purpose : Called when GEOM module is deactivated
1183 //=======================================================================
1184 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1186 setMenuShown( false );
1187 setToolShown( false );
1189 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1190 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1192 EmitSignalCloseAllDialogs();
1194 GUIMap::Iterator it;
1195 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1196 it.data()->deactivate();
1198 // Unset actions accelerator keys
1199 //action(111)->setAccel(QKeySequence()); // Import
1200 //action(121)->setAccel(QKeySequence()); // Export
1201 action(111)->setEnabled(false); // Import
1202 action(121)->setEnabled(false); // Export
1204 myOCCSelectors.clear();
1205 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1207 myVTKSelectors.clear();
1208 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1210 return SalomeApp_Module::deactivateModule( study );
1213 //=================================================================================
1214 // function : GeometryGUI::DefinePopup()
1215 // purpose : Called from desktop to define popup menu [static]
1216 //=================================================================================
1218 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1220 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1221 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1226 if ( theParent == "Viewer" ) {
1227 if ( Sel->IObjectCount() == 0 )
1228 theContext = "NothingSelected";
1231 if ( Sel->IObjectCount() == 1 ) {
1232 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1233 if( IO->hasEntry() ) {
1234 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1235 if ( !sobj->_is_nil() ) {
1236 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1237 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1238 // component is selected
1239 theObject = "Component";
1242 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1243 if ( !CORBA::is_nil( aGObj ) ) {
1244 switch( aGObj->GetType() ) {
1246 theObject = "Group";
1249 theObject = "Shape";
1259 //=================================================================================
1260 // function : GeometryGUI::CustomPopup()
1261 // purpose : Called from desktop to create popup menu [static]
1262 //=================================================================================
1263 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1264 const QString& theParent, const QString& theObject)
1266 GeometryGUI* geomGUI = GetGeomGUI();
1268 // Deactivate any non modal dialog box to get the neutral point
1269 geomGUI->EmitSignalDeactivateDialog();
1270 QAD_Study* anActiveStudy = parent->getActiveStudy();
1271 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1272 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1273 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1274 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1275 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1276 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1277 int aDisplayMode = 0;
1280 if ( aViewFrame->getTypeView() == VIEW_OCC )
1281 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1282 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1283 aDisplayMode = (dynamic_cast<SVTK_ViewFrame*>( aViewFrame )->getRWInteractor()->GetDisplayMode();
1285 int nbSel = Sel->IObjectCount();
1288 ////// NOTHING SELECTED
1291 else if ( nbSel == 1 ) {
1292 ////// SINGLE OBJECT SELECTION
1293 if ( parentComponent != parent->getActiveComponent() ) {
1294 ////// selected object does not belong to GEOM module:
1295 // remove all commands except Display/Erase...
1297 int id = popup->idAt( 0 );
1298 if ( id <= QAD_TopLabel_Popup_ID )
1299 popup->removeItemAt( 0 );
1305 ////// selected object belong to the GEOM module
1306 // get interactive object
1307 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1308 objectName = IObject->getName();
1309 // if object has entry get SObject
1310 SALOMEDS::SObject_var SO;
1311 if ( IObject->hasEntry() )
1312 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1314 if ( theObject == "Component" ) {
1315 ////// menu for component
1316 if ( !isOCCViewer && !isVTKViewer ) {
1317 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1318 popup->removeItem( QAD_Display_Popup_ID );
1319 popup->removeItem( QAD_Erase_Popup_ID );
1323 ////// not component (should be shape)
1324 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1325 popup->removeItem( 804 ); // "Add in Study"
1327 // Here could be analysis of the geom shape's type
1330 SALOMEDS::GenericAttribute_var aTmpAttr;
1331 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1332 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1334 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1335 if ( theObject == "Shape" )
1336 popup->removeItem( 800 ); // Create Group
1337 else if ( theObject == "Group" )
1338 popup->removeItem( 801 ); // Edit Group
1341 if ( isOCCViewer || isVTKViewer ) {
1342 ////// current viewer is OCC or VTK
1343 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1344 if ( aViewFrame->isVisible( IObject ) ) {
1345 ////// object is already displayed in the viewer
1346 popup->removeItem( QAD_Display_Popup_ID );
1347 if ( isOCCViewer ) {
1348 ////// OCC viewer only
1349 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1350 if ( occPrs && !occPrs->IsNull() ) {
1351 AIS_ListOfInteractive ioList;
1352 occPrs->GetObjects( ioList );
1353 QMenuItem* mi = popup->findItem( 803 );
1354 if ( mi && mi->popup() ) {
1355 if ( ioList.First()->DisplayMode() == 0 )
1356 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1357 else if ( ioList.First()->DisplayMode() == 1 )
1358 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1359 else if ( ioList.First()->DisplayMode() < 0 )
1360 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1365 ////// VTK viewer only
1366 popup->removeItem( 8034 ); // "Isos"
1367 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1368 if ( vtkPrs && !vtkPrs->IsNull() ) {
1369 vtkActorCollection* actorList = vtkPrs->GetObjects();
1370 actorList->InitTraversal();
1371 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1372 QMenuItem* mi = popup->findItem( 803 );
1373 if ( ac && mi && mi->popup() ) {
1374 if ( ac->getDisplayMode() == 0 )
1375 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1376 else if ( ac->getDisplayMode() == 1 )
1377 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1379 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1385 ////// object is not yet displayed in the viewer
1386 popup->removeItem( 803 ); // "Display Mode"
1387 popup->removeItem( 8032 ); // "Color"
1388 popup->removeItem( 8033 ); // "Transparency"
1389 popup->removeItem( 8034 ); // "Isos"
1390 popup->removeItem( QAD_Erase_Popup_ID );
1395 ////// other viewer type (neither OCC nor VTK)
1396 popup->removeItem( 803 ); // "Display Mode"
1397 popup->removeItem( 8032 ); // "Color"
1398 popup->removeItem( 8033 ); // "Transparency"
1399 popup->removeItem( 8034 ); // "Isos"
1400 popup->removeItem( QAD_Display_Popup_ID );
1401 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1402 popup->removeItem( QAD_Erase_Popup_ID );
1408 ////// MULTIPLE SELECTION
1409 if ( parentComponent != parent->getActiveComponent() ) {
1410 ////// not GEOM module objects or objects belong to different modules
1411 // remove all commands except Display/Erase...
1413 int id = popup->idAt( 0 );
1414 if ( id <= QAD_TopLabel_Popup_ID )
1415 popup->removeItemAt( 0 );
1419 if ( parentComponent.isNull() ) {
1420 ////// objects belong to different modules
1421 popup->removeItem(QAD_Display_Popup_ID);
1422 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1423 popup->removeItem(QAD_Erase_Popup_ID);
1426 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1430 ////// all selected objects belong to GEOM module
1431 popup->removeItem( 901 ); // "Rename"
1433 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1434 bool isComponent = false;
1435 bool needOpen = false;
1436 bool needDisplay = false;
1437 bool needErase = false;
1438 int needToPublish = 0;
1440 for( ;It.More();It.Next() ) {
1441 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1443 if ( aViewFrame->isVisible( anIObject ) )
1448 if( anIObject->hasEntry() ) {
1449 needToPublish = -1; /////// VSR : TO BE REMOVED
1450 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1451 SALOMEDS::GenericAttribute_var aTmpAttr;
1452 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1453 needOpen = true; /////// VSR : TO BE REMOVED
1454 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1458 if ( needToPublish != -1 ) needToPublish = 1;
1461 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1462 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1463 popup->removeItem( 803 ); // "Display Mode"
1464 popup->removeItem( 8032 ); // "Color"
1465 popup->removeItem( 8033 ); // "Transparency"
1466 popup->removeItem( 8034 ); // "Isos"
1467 popup->removeItem( 804 ); // "Add in Study"
1468 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1469 popup->removeItem( QAD_Display_Popup_ID );
1470 popup->removeItem( QAD_Erase_Popup_ID );
1473 popup->removeItem( 9024 ); // "Open"
1474 if ( needToPublish <= 0 )
1475 popup->removeItem( 804 ); // "Add in Study"
1478 popup->removeItem( 803 ); // "Display Mode"
1479 popup->removeItem( 8032 ); // "Color"
1480 popup->removeItem( 8033 ); // "Transparency"
1481 popup->removeItem( 8034 ); // "Isos"
1482 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1486 popup->removeItem( QAD_Display_Popup_ID );
1488 popup->removeItem( QAD_Erase_Popup_ID );
1490 popup->removeItem( 8034 ); // "Isos"
1495 // check popup for unnecessary separators
1496 QAD_Tools::checkPopup( popup );
1497 // find popup menu's TopLabel item (with title)
1498 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1499 if ( topItem >= 0 ) {
1500 // remove popup menu's title item
1501 popup->removeItem( QAD_TopLabel_Popup_ID );
1502 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1503 // set bold font for popup menu's title
1504 QFont f = popup->font(); f.setBold( TRUE );
1505 popup->removeItem( QAD_TopLabel_Popup_ID );
1506 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1515 //=======================================================================
1516 // function : GeometryGUI::BuildPresentation()
1518 //=======================================================================
1519 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1521 //GEOM_Displayer().Display( io, false, win );
1524 //=======================================================================
1525 // function : onWindowActivated()
1526 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1527 //=======================================================================
1528 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1533 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1534 // const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1536 // disable non-OCC viewframe menu commands
1537 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1538 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1539 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1540 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1541 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1542 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1543 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1544 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1546 action( 800 )->setEnabled( ViewOCC ); // Create Group
1547 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1549 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1552 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1554 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1555 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1558 void GeometryGUI::viewManagers( QStringList& lst ) const
1560 lst.append( OCCViewer_Viewer::Type() );
1563 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1565 if ( vm->getType() == OCCViewer_Viewer::Type() )
1567 qDebug( "connect" );
1568 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1569 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1570 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1571 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1572 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1573 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1576 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1577 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1579 // disable OCC selectors
1580 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1581 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1582 sr->setEnabled(true);
1584 else if ( vm->getType() == SVTK_Viewer::Type() )
1586 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1587 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1589 // disable VTK selectors
1590 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1591 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1592 sr->setEnabled(true);
1596 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1598 SUIT_ViewModel* viewer = vm->getViewModel();
1599 if ( vm->getType() == OCCViewer_Viewer::Type() )
1601 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1602 if ( sr->viewer() == viewer )
1604 myOCCSelectors.remove( sr );
1608 if ( vm->getType() == SVTK_Viewer::Type() )
1610 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1611 if ( sr->viewer() == viewer )
1613 myVTKSelectors.remove( sr );
1619 QString GeometryGUI::engineIOR() const
1621 if ( !CORBA::is_nil( GetGeomGen() ) )
1622 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1623 return QString( "" );
1626 LightApp_Selection* GeometryGUI::createSelection() const
1628 return new GEOMGUI_Selection();
1631 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1633 SalomeApp_Module::contextMenuPopup( client, menu, title );
1635 getApp()->selectionMgr()->selectedObjects( lst );
1636 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1637 Handle(SALOME_InteractiveObject) io = lst.First();
1638 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1639 _PTR(Study) study = appStudy->studyDS();
1640 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1642 title = QString( obj->GetName().c_str() );
1646 void GeometryGUI::createPreferences()
1648 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1650 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1651 setPreferenceProperty( genGroup, "columns", 1 );
1653 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1654 LightApp_Preferences::Selector, "Geometry", "display_mode" );
1656 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1657 LightApp_Preferences::Color, "Geometry", "shading_color" );
1659 addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1660 LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1662 addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1663 LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1665 addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1666 LightApp_Preferences::Color, "Geometry", "line_color" );
1668 addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1669 LightApp_Preferences::Color, "Geometry", "point_color" );
1671 addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1672 LightApp_Preferences::Color, "Geometry", "isos_color" );
1674 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1675 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1677 int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1679 int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1680 LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1682 int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1683 LightApp_Preferences::DblSpin, "Geometry", "marker_scale" );
1685 // Set property for default display mode
1686 QStringList aModesList;
1687 aModesList.append( tr("MEN_WIREFRAME") );
1688 aModesList.append( tr("MEN_SHADING") );
1690 QValueList<QVariant> anIndexesList;
1691 anIndexesList.append(0);
1692 anIndexesList.append(1);
1694 setPreferenceProperty( dispmode, "strings", aModesList );
1695 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1697 // Set property for step value for spinboxes
1698 setPreferenceProperty( step, "min", 0.001 );
1699 setPreferenceProperty( step, "max", 10000 );
1700 setPreferenceProperty( step, "precision", 3 );
1702 // Set property for type of vertex marker
1703 QStringList aTypeOfMarkerList;
1704 QValueList<QVariant> anTypeOfMarkerIndexesList;
1706 aTypeOfMarkerList.append( tr("TOM_PLUS") );
1707 anTypeOfMarkerIndexesList.append(Aspect_TOM_PLUS);
1709 aTypeOfMarkerList.append( tr("TOM_POINT") );
1710 anTypeOfMarkerIndexesList.append(Aspect_TOM_POINT);
1712 aTypeOfMarkerList.append( tr("TOM_STAR") );
1713 anTypeOfMarkerIndexesList.append(Aspect_TOM_STAR);
1715 aTypeOfMarkerList.append( tr("TOM_O") );
1716 anTypeOfMarkerIndexesList.append(Aspect_TOM_O);
1718 aTypeOfMarkerList.append( tr("TOM_X") );
1719 anTypeOfMarkerIndexesList.append(Aspect_TOM_X);
1721 aTypeOfMarkerList.append( tr("TOM_O_POINT") );
1722 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_POINT);
1724 aTypeOfMarkerList.append( tr("TOM_O_PLUS") );
1725 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_PLUS);
1727 aTypeOfMarkerList.append( tr("TOM_O_STAR") );
1728 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_STAR);
1730 aTypeOfMarkerList.append( tr("TOM_O_X") );
1731 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_X);
1734 setPreferenceProperty( typeOfMarker, "strings", aTypeOfMarkerList );
1735 setPreferenceProperty( typeOfMarker, "indexes", anTypeOfMarkerIndexesList );
1737 // Set property for Vertex Marker scale
1738 setPreferenceProperty( markerScale, "min", 1. );
1739 setPreferenceProperty( markerScale, "max", 7. );
1740 setPreferenceProperty( markerScale, "precision", 0.01 );
1741 setPreferenceProperty( markerScale, "step", 0.5 );
1745 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1747 if (section == "Geometry") {
1748 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1749 if (param == QString("SettingsGeomStep")) {
1750 double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1751 EmitSignalDefaultStepValueChanged(spin_step);
1756 LightApp_Displayer* GeometryGUI::displayer()
1759 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );