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 <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 <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() == SVTK_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 SVTK_ViewWindow* vw = dynamic_cast<SVTK_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() == SVTK_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 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
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 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
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 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
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 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
602 SVTK_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 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
638 SVTK_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 );
1002 because of these items are accessible through object browser and viewers
1003 we have removed they from main menu
1005 createMenu( 216, viewId, -1 );
1006 createMenu( 213, viewId, -1 );
1007 createMenu( 215, viewId, -1 );
1010 // ---- create toolbars --------------------------
1012 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1013 createTool( 4011, basicTbId );
1014 createTool( 4012, basicTbId );
1015 createTool( 4013, basicTbId );
1016 createTool( 4014, basicTbId );
1017 createTool( 4015, basicTbId );
1018 createTool( 4019, basicTbId );
1019 createTool( 4016, basicTbId );
1020 createTool( 4017, basicTbId );
1021 createTool( 4018, basicTbId );
1022 createTool( 4020, basicTbId );
1024 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1025 createTool( 4021, primTbId );
1026 createTool( 4022, primTbId );
1027 createTool( 4023, primTbId );
1028 createTool( 4024, primTbId );
1029 createTool( 4025, primTbId );
1031 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1032 createTool( 5011, boolTbId );
1033 createTool( 5012, boolTbId );
1034 createTool( 5013, boolTbId );
1035 createTool( 5014, boolTbId );
1037 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1038 createTool( 4031, genTbId );
1039 createTool( 4032, genTbId );
1040 createTool( 4033, genTbId );
1041 createTool( 4034, genTbId );
1043 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1044 createTool( 5021, transTbId );
1045 createTool( 5022, transTbId );
1046 createTool( 5023, transTbId );
1047 createTool( 5024, transTbId );
1048 createTool( 5025, transTbId );
1049 createTool( 5026, transTbId );
1050 createTool( separator(), transTbId );
1051 createTool( 5027, transTbId );
1052 createTool( 5028, transTbId );
1054 QtxPopupMgr* mgr = popupMgr();
1055 mgr->insert( action( 901 ), -1, -1 ); // rename
1056 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1057 mgr->insert( action( 8001 ), -1, -1 ); // create group
1058 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1059 mgr->insert( action( 801 ), -1, -1 ); // edit group
1060 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1061 mgr->insert( separator(), -1, -1 ); // -----------
1062 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1063 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1064 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1065 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Wireframe'", false );
1066 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1067 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1068 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Shading'", false );
1069 mgr->insert( separator(), -1, -1 ); // -----------
1070 mgr->insert( action( 8032 ), -1, -1 ); // color
1071 mgr->setRule( action( 8032 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1072 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1073 mgr->setRule( action( 8033 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1074 mgr->insert( action( 8034 ), -1, -1 ); // isos
1075 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true );
1076 mgr->insert( separator(), -1, -1 ); // -----------
1080 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1081 onlyComponent = "((type='Component') and selcount=1)",
1082 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1083 types = "'Shape' 'Group'";
1085 mgr->insert( action( 216 ), -1, -1 ); // display
1086 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), true );
1088 mgr->insert( action( 215 ), -1, -1 ); // erase
1089 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), true );
1091 mgr->insert( action( 214 ), -1, -1 ); // erase All
1092 mgr->setRule( action( 214 ), "client='OCCViewer' or client='VTKViewer'", true );
1094 mgr->insert( action( 213 ), -1, -1 ); // display only
1095 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), true );
1096 mgr->insert( separator(), -1, -1 );
1098 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1101 //=======================================================================
1102 // function : GeometryGUI::Deactivate()
1103 // purpose : Called when GEOM module is deactivated [ static ]
1104 //=======================================================================
1105 bool GeometryGUI::activateModule( SUIT_Study* study )
1107 if ( CORBA::is_nil( myComponentGeom ) )
1110 bool res = SalomeApp_Module::activateModule( study );
1115 setMenuShown( true );
1116 setToolShown( true );
1118 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1119 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1121 GUIMap::Iterator it;
1122 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1123 it.data()->activate( application()->desktop() );
1125 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1126 SUIT_ViewManager* vm;
1127 ViewManagerList OCCViewManagers, VTKViewManagers;
1128 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1129 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1130 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1131 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1132 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1133 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1135 // disable OCC selectors
1136 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1137 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1138 sr->setEnabled(true);
1140 // disable VTK selectors
1141 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1142 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1143 sr->setEnabled(true);
1149 //=======================================================================
1150 // function : GeometryGUI::Deactivate()
1151 // purpose : Called when GEOM module is deactivated [ static ]
1152 //=======================================================================
1153 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1155 setMenuShown( false );
1156 setToolShown( false );
1158 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1159 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1161 EmitSignalCloseAllDialogs();
1163 GUIMap::Iterator it;
1164 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1165 it.data()->deactivate();
1167 myOCCSelectors.clear();
1168 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1170 myVTKSelectors.clear();
1171 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1173 return SalomeApp_Module::deactivateModule( study );
1176 //=================================================================================
1177 // function : GeometryGUI::DefinePopup()
1178 // purpose : Called from desktop to define popup menu [static]
1179 //=================================================================================
1181 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1183 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1184 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1189 if ( theParent == "Viewer" ) {
1190 if ( Sel->IObjectCount() == 0 )
1191 theContext = "NothingSelected";
1194 if ( Sel->IObjectCount() == 1 ) {
1195 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1196 if( IO->hasEntry() ) {
1197 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1198 if ( !sobj->_is_nil() ) {
1199 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1200 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1201 // component is selected
1202 theObject = "Component";
1205 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1206 if ( !CORBA::is_nil( aGObj ) ) {
1207 switch( aGObj->GetType() ) {
1209 theObject = "Group";
1212 theObject = "Shape";
1222 //=================================================================================
1223 // function : GeometryGUI::CustomPopup()
1224 // purpose : Called from desktop to create popup menu [static]
1225 //=================================================================================
1226 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1227 const QString& theParent, const QString& theObject)
1229 GeometryGUI* geomGUI = GetGeomGUI();
1231 // Deactivate any non modal dialog box to get the neutral point
1232 geomGUI->EmitSignalDeactivateDialog();
1233 QAD_Study* anActiveStudy = parent->getActiveStudy();
1234 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1235 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1236 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1237 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1238 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1239 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1240 int aDisplayMode = 0;
1243 if ( aViewFrame->getTypeView() == VIEW_OCC )
1244 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1245 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1246 aDisplayMode = (dynamic_cast<SVTK_ViewFrame*>( aViewFrame )->getRWInteractor()->GetDisplayMode();
1248 int nbSel = Sel->IObjectCount();
1251 ////// NOTHING SELECTED
1254 else if ( nbSel == 1 ) {
1255 ////// SINGLE OBJECT SELECTION
1256 if ( parentComponent != parent->getActiveComponent() ) {
1257 ////// selected object does not belong to GEOM module:
1258 // remove all commands except Display/Erase...
1260 int id = popup->idAt( 0 );
1261 if ( id <= QAD_TopLabel_Popup_ID )
1262 popup->removeItemAt( 0 );
1268 ////// selected object belong to the GEOM module
1269 // get interactive object
1270 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1271 objectName = IObject->getName();
1272 // if object has entry get SObject
1273 SALOMEDS::SObject_var SO;
1274 if ( IObject->hasEntry() )
1275 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1277 if ( theObject == "Component" ) {
1278 ////// menu for component
1279 if ( !isOCCViewer && !isVTKViewer ) {
1280 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1281 popup->removeItem( QAD_Display_Popup_ID );
1282 popup->removeItem( QAD_Erase_Popup_ID );
1286 ////// not component (should be shape)
1287 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1288 popup->removeItem( 804 ); // "Add in Study"
1290 // Here could be analysis of the geom shape's type
1293 SALOMEDS::GenericAttribute_var aTmpAttr;
1294 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1295 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1297 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1298 if ( theObject == "Shape" )
1299 popup->removeItem( 800 ); // Create Group
1300 else if ( theObject == "Group" )
1301 popup->removeItem( 801 ); // Edit Group
1304 if ( isOCCViewer || isVTKViewer ) {
1305 ////// current viewer is OCC or VTK
1306 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1307 if ( aViewFrame->isVisible( IObject ) ) {
1308 ////// object is already displayed in the viewer
1309 popup->removeItem( QAD_Display_Popup_ID );
1310 if ( isOCCViewer ) {
1311 ////// OCC viewer only
1312 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1313 if ( occPrs && !occPrs->IsNull() ) {
1314 AIS_ListOfInteractive ioList;
1315 occPrs->GetObjects( ioList );
1316 QMenuItem* mi = popup->findItem( 803 );
1317 if ( mi && mi->popup() ) {
1318 if ( ioList.First()->DisplayMode() == 0 )
1319 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1320 else if ( ioList.First()->DisplayMode() == 1 )
1321 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1322 else if ( ioList.First()->DisplayMode() < 0 )
1323 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1328 ////// VTK viewer only
1329 popup->removeItem( 8034 ); // "Isos"
1330 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1331 if ( vtkPrs && !vtkPrs->IsNull() ) {
1332 vtkActorCollection* actorList = vtkPrs->GetObjects();
1333 actorList->InitTraversal();
1334 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1335 QMenuItem* mi = popup->findItem( 803 );
1336 if ( ac && mi && mi->popup() ) {
1337 if ( ac->getDisplayMode() == 0 )
1338 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1339 else if ( ac->getDisplayMode() == 1 )
1340 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1342 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1348 ////// object is not yet displayed in the viewer
1349 popup->removeItem( 803 ); // "Display Mode"
1350 popup->removeItem( 8032 ); // "Color"
1351 popup->removeItem( 8033 ); // "Transparency"
1352 popup->removeItem( 8034 ); // "Isos"
1353 popup->removeItem( QAD_Erase_Popup_ID );
1358 ////// other viewer type (neither OCC nor VTK)
1359 popup->removeItem( 803 ); // "Display Mode"
1360 popup->removeItem( 8032 ); // "Color"
1361 popup->removeItem( 8033 ); // "Transparency"
1362 popup->removeItem( 8034 ); // "Isos"
1363 popup->removeItem( QAD_Display_Popup_ID );
1364 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1365 popup->removeItem( QAD_Erase_Popup_ID );
1371 ////// MULTIPLE SELECTION
1372 if ( parentComponent != parent->getActiveComponent() ) {
1373 ////// not GEOM module objects or objects belong to different modules
1374 // remove all commands except Display/Erase...
1376 int id = popup->idAt( 0 );
1377 if ( id <= QAD_TopLabel_Popup_ID )
1378 popup->removeItemAt( 0 );
1382 if ( parentComponent.isNull() ) {
1383 ////// objects belong to different modules
1384 popup->removeItem(QAD_Display_Popup_ID);
1385 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1386 popup->removeItem(QAD_Erase_Popup_ID);
1389 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1393 ////// all selected objects belong to GEOM module
1394 popup->removeItem( 901 ); // "Rename"
1396 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1397 bool isComponent = false;
1398 bool needOpen = false;
1399 bool needDisplay = false;
1400 bool needErase = false;
1401 int needToPublish = 0;
1403 for( ;It.More();It.Next() ) {
1404 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1406 if ( aViewFrame->isVisible( anIObject ) )
1411 if( anIObject->hasEntry() ) {
1412 needToPublish = -1; /////// VSR : TO BE REMOVED
1413 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1414 SALOMEDS::GenericAttribute_var aTmpAttr;
1415 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1416 needOpen = true; /////// VSR : TO BE REMOVED
1417 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1421 if ( needToPublish != -1 ) needToPublish = 1;
1424 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1425 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1426 popup->removeItem( 803 ); // "Display Mode"
1427 popup->removeItem( 8032 ); // "Color"
1428 popup->removeItem( 8033 ); // "Transparency"
1429 popup->removeItem( 8034 ); // "Isos"
1430 popup->removeItem( 804 ); // "Add in Study"
1431 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1432 popup->removeItem( QAD_Display_Popup_ID );
1433 popup->removeItem( QAD_Erase_Popup_ID );
1436 popup->removeItem( 9024 ); // "Open"
1437 if ( needToPublish <= 0 )
1438 popup->removeItem( 804 ); // "Add in Study"
1441 popup->removeItem( 803 ); // "Display Mode"
1442 popup->removeItem( 8032 ); // "Color"
1443 popup->removeItem( 8033 ); // "Transparency"
1444 popup->removeItem( 8034 ); // "Isos"
1445 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1449 popup->removeItem( QAD_Display_Popup_ID );
1451 popup->removeItem( QAD_Erase_Popup_ID );
1453 popup->removeItem( 8034 ); // "Isos"
1458 // check popup for unnecessary separators
1459 QAD_Tools::checkPopup( popup );
1460 // find popup menu's TopLabel item (with title)
1461 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1462 if ( topItem >= 0 ) {
1463 // remove popup menu's title item
1464 popup->removeItem( QAD_TopLabel_Popup_ID );
1465 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1466 // set bold font for popup menu's title
1467 QFont f = popup->font(); f.setBold( TRUE );
1468 popup->removeItem( QAD_TopLabel_Popup_ID );
1469 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1478 //=======================================================================
1479 // function : GeometryGUI::BuildPresentation()
1481 //=======================================================================
1482 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1484 //GEOM_Displayer().Display( io, false, win );
1487 //=======================================================================
1488 // function : setCommandsEnabled()
1489 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1490 //=======================================================================
1491 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1496 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1497 // const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1499 // disable non-OCC viewframe menu commands
1500 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1501 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1502 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1503 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1504 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1505 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1506 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1507 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1509 action( 800 )->setEnabled( ViewOCC ); // Create Group
1510 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1512 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1515 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1517 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1518 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1521 void GeometryGUI::viewManagers( QStringList& lst ) const
1523 lst.append( OCCViewer_Viewer::Type() );
1526 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1528 if ( vm->getType() == OCCViewer_Viewer::Type() )
1530 qDebug( "connect" );
1531 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1532 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1533 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1534 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1535 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1536 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1539 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1540 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1542 // disable OCC selectors
1543 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1544 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1545 sr->setEnabled(true);
1547 else if ( vm->getType() == SVTK_Viewer::Type() )
1549 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1550 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1552 // disable VTK selectors
1553 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1554 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1555 sr->setEnabled(true);
1559 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1561 SUIT_ViewModel* viewer = vm->getViewModel();
1562 if ( vm->getType() == OCCViewer_Viewer::Type() )
1564 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1565 if ( sr->viewer() == viewer )
1567 myOCCSelectors.remove( sr );
1571 if ( vm->getType() == SVTK_Viewer::Type() )
1573 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1574 if ( sr->viewer() == viewer )
1576 myVTKSelectors.remove( sr );
1582 QString GeometryGUI::engineIOR() const
1584 if ( !CORBA::is_nil( GetGeomGen() ) )
1585 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1586 return QString( "" );
1589 LightApp_Selection* GeometryGUI::createSelection() const
1591 return new GEOMGUI_Selection();
1594 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1596 SalomeApp_Module::contextMenuPopup( client, menu, title );
1598 getApp()->selectionMgr()->selectedObjects( lst );
1599 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1600 Handle(SALOME_InteractiveObject) io = lst.First();
1601 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1602 _PTR(Study) study = appStudy->studyDS();
1603 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1605 title = QString( obj->GetName().c_str() );
1609 void GeometryGUI::createPreferences()
1611 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1613 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1614 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1615 LightApp_Preferences::Color, "Geometry", "shading_color" );
1616 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1617 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1618 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1619 LightApp_Preferences::Selector, "Geometry", "display_mode" );
1621 setPreferenceProperty( genGroup, "columns", 1 );
1623 setPreferenceProperty( step, "min", 0.001 );
1624 setPreferenceProperty( step, "max", 10000 );
1625 setPreferenceProperty( step, "precision", 3 );
1627 // Set property for default display mode
1628 QStringList aModesList;
1629 aModesList.append( tr("MEN_WIREFRAME") );
1630 aModesList.append( tr("MEN_SHADING") );
1632 QValueList<QVariant> anIndexesList;
1633 anIndexesList.append(0);
1634 anIndexesList.append(1);
1636 setPreferenceProperty( dispmode, "strings", aModesList );
1637 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1640 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1644 LightApp_Displayer* GeometryGUI::displayer()
1647 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );