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()
84 // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
85 if (CORBA::is_nil(myComponentGeom))
87 return GeometryGUI::myComponentGeom;
90 bool GeometryGUI::InitGeomGen()
93 if( CORBA::is_nil( myComponentGeom ) ) return false;
97 //=======================================================================
98 // function : ClientSObjectToObject
100 //=======================================================================
101 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
103 _PTR(GenericAttribute) anAttr;
104 CORBA::Object_var anObj;
106 std::string aValue = theSObject->GetIOR();
107 if (strcmp(aValue.c_str(), "") != 0) {
108 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
109 anObj = anORB->string_to_object(aValue.c_str());
112 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
114 return anObj._retn();
117 //=======================================================================
118 // function : ClientStudyToStudy
120 //=======================================================================
121 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
123 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
124 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
125 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
126 int aStudyID = theStudy->StudyId();
127 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
128 return aDSStudy._retn();
131 //=================================================================================
132 // class : CustomItem
133 // purpose : Set Font to a text.
134 //=================================================================================
135 class CustomItem : public QCustomMenuItem
138 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
141 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
144 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
145 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
146 p->setFont( myFont );
147 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
153 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
156 bool fullSpan() const
166 //=======================================================================
167 // function : GeometryGUI::GeometryGUI()
168 // purpose : Constructor
169 //=======================================================================
170 GeometryGUI::GeometryGUI() :
171 SalomeApp_Module( "GEOM" )
173 if ( CORBA::is_nil( myComponentGeom ) )
175 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
176 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
177 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
181 myActiveDialogBox = 0;
184 gp_Pnt origin = gp_Pnt(0., 0., 0.);
185 gp_Dir direction = gp_Dir(0., 0., 1.);
186 myWorkingPlane = gp_Ax3(origin, direction);
188 myOCCSelectors.setAutoDelete( true );
189 myVTKSelectors.setAutoDelete( true );
194 //=======================================================================
195 // function : GeometryGUI::~GeometryGUI()
196 // purpose : Destructor
197 //=======================================================================
198 GeometryGUI::~GeometryGUI()
202 //=======================================================================
203 // function : GeometryGUI::getLibrary()
204 // purpose : get or load GUI library by name [ internal ]
205 //=======================================================================
206 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
207 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
209 if ( !myGUIMap.contains( libraryName ) ) {
210 // try to load library if it is not loaded yet
213 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
214 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
216 if( ( libs = getenv( "PATH" ) ) ) {
217 QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries
219 for( int i = dirList.count()-1; i >= 0; i-- ) {
220 QString dir = dirList[ i ];
221 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
223 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
224 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
226 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
227 continue; // continue search further
229 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
230 if ( osdF != NULL ) {
231 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
232 GEOMGUI* libGUI = (*func)(this);
234 myGUIMap[ libraryName ] = libGUI;
235 break; // found and loaded!
242 if ( myGUIMap.contains( libraryName ) )
243 // library is successfully loaded
244 return myGUIMap[ libraryName ];
248 //=======================================================================
249 // function : GeometryGUI::ActiveWorkingPlane()
250 // purpose : Activate Working Plane View
251 //=======================================================================
252 void GeometryGUI::ActiveWorkingPlane()
254 gp_Dir DZ = myWorkingPlane.Direction();
255 gp_Dir DY = myWorkingPlane.YDirection();
257 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
258 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
259 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
262 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
264 Handle(V3d_View) view3d = vw->getViewPort()->getView();
266 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
267 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
273 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
275 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
277 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
278 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
279 camera->SetFocalPoint(0,0,0);
286 //=======================================================================
287 // function : GeometryGUI::SetActiveDialogBox()
288 // purpose : Set active dialog box
289 //=======================================================================
290 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
292 myActiveDialogBox = (QDialog*)aDlg;
295 //=======================================================================
296 // function : GeometryGUI::EmitSignalDeactivateDialog()
297 // purpose : Emit a signal to deactivate the active dialog Box
298 //=======================================================================
299 void GeometryGUI::EmitSignalDeactivateDialog()
301 emit SignalDeactivateActiveDialog();
304 //=======================================================================
305 // function : GeometryGUI::EmitSignalCloseAllDialogs()
306 // purpose : Emit a signal to close all non modal dialogs box
307 //=======================================================================
308 void GeometryGUI::EmitSignalCloseAllDialogs()
310 emit SignalCloseAllDialogs();
313 //=======================================================================
314 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
315 // purpose : Emit a signal to inform that default real spin box step has
317 //=======================================================================
318 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
320 emit SignalDefaultStepValueChanged(newVal);
323 //=======================================================================
324 // function : GeometryGUI::OnGUIEvent()
325 // purpose : common slot for all menu/toolbar actions
326 //=======================================================================
327 void GeometryGUI::OnGUIEvent()
329 const QObject* obj = sender();
330 if ( !obj || !obj->inherits( "QAction" ) )
332 int id = actionId((QAction*)obj);
337 //=======================================================================
338 // function : GeometryGUI::OnGUIEvent()
339 // purpose : manage all events on GUI [static]
340 //=======================================================================
341 void GeometryGUI::OnGUIEvent( int id )
343 SUIT_Desktop* desk = application()->desktop();
345 // check type of the active viewframe
346 SUIT_ViewWindow* window = desk->activeWindow();
347 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
348 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
349 // if current viewframe is not of OCC and not of VTK type - return immediately
350 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
351 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
352 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
355 // fix for IPAL9103, point 2
356 if ( CORBA::is_nil( GetGeomGen() ) ) {
357 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
361 GEOMGUI* library = 0;
362 // try to get-or-load corresponding GUI library
363 if( id == 111 || // MENU FILE - IMPORT BREP
364 id == 112 || // MENU FILE - IMPORT IGES
365 id == 113 || // MENU FILE - IMPORT STEP
366 id == 121 || // MENU FILE - EXPORT BREP
367 id == 122 || // MENU FILE - EXPORT IGES
368 id == 123 || // MENU FILE - EXPORT STEP
369 id == 31 || // MENU EDIT - COPY
370 id == 33 || // MENU EDIT - DELETE
371 id == 411 || // MENU SETTINGS - ADD IN STUDY
372 id == 412 || // MENU SETTINGS - SHADING COLOR
373 id == 413 || // MENU SETTINGS - ISOS
374 id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
375 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
376 id == 8032 || // POPUP VIEWER - COLOR
377 id == 8033 || // POPUP VIEWER - TRANSPARENCY
378 id == 8034 || // POPUP VIEWER - ISOS
379 id == 804 || // POPUP VIEWER - ADD IN STUDY
380 id == 901 || // OBJECT BROWSER - RENAME
381 id == 9024 ) { // OBJECT BROWSER - OPEN
382 //cout << "id " << id << " received" << endl;
384 library = getLibrary( "libGEOMToolsGUI.so" );
386 library = getLibrary( "GEOMToolsGUI.dll" );
389 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
390 id == 212 || // MENU VIEW - DISPLAY ALL
391 id == 213 || // MENU VIEW - DISPLAY ONLY
392 id == 214 || // MENU VIEW - ERASE ALL
393 id == 215 || // MENU VIEW - ERASE
394 id == 216 || // MENU VIEW - DISPLAY
395 id == 80311 || // POPUP VIEWER - WIREFRAME
396 id == 80312 ) { // POPUP VIEWER - SHADING
398 library = getLibrary( "libDisplayGUI.so" );
400 library = getLibrary( "DisplayGUI.dll" );
403 else if( id == 4011 || // MENU BASIC - POINT
404 id == 4012 || // MENU BASIC - LINE
405 id == 4013 || // MENU BASIC - CIRCLE
406 id == 4014 || // MENU BASIC - ELLIPSE
407 id == 4015 || // MENU BASIC - ARC
408 id == 4016 || // MENU BASIC - VECTOR
409 id == 4017 || // MENU BASIC - PLANE
410 id == 4018 || // MENU BASIC - WPLANE
411 id == 4019 || // MENU BASIC - CURVE
412 id == 4020 ) { // MENU BASIC - REPAIR
414 library = getLibrary( "libBasicGUI.so" );
416 library = getLibrary( "BasicGUI.dll" );
419 else if( id == 4021 || // MENU PRIMITIVE - BOX
420 id == 4022 || // MENU PRIMITIVE - CYLINDER
421 id == 4023 || // MENU PRIMITIVE - SPHERE
422 id == 4024 || // MENU PRIMITIVE - TORUS
423 id == 4025 ) { // MENU PRIMITIVE - CONE
425 library = getLibrary( "libPrimitiveGUI.so" );
427 library = getLibrary( "PrimitiveGUI.dll" );
430 else if( id == 4031 || // MENU GENERATION - PRISM
431 id == 4032 || // MENU GENERATION - REVOLUTION
432 id == 4033 || // MENU GENERATION - FILLING
433 id == 4034 ) { // MENU GENERATION - PIPE
435 library = getLibrary( "libGenerationGUI.so" );
437 library = getLibrary( "GenerationGUI.dll" );
440 else if( id == 404 || // MENU ENTITY - SKETCHER
441 id == 407 ) { // MENU ENTITY - EXPLODE
443 library = getLibrary( "libEntityGUI.so" );
445 library = getLibrary( "EntityGUI.dll" );
448 else if( id == 4081 || // MENU BUILD - EDGE
449 id == 4082 || // MENU BUILD - WIRE
450 id == 4083 || // MENU BUILD - FACE
451 id == 4084 || // MENU BUILD - SHELL
452 id == 4085 || // MENU BUILD - SOLID
453 id == 4086 ) { // MENU BUILD - COMPUND
455 library = getLibrary( "libBuildGUI.so" );
457 library = getLibrary( "BuildGUI.dll" );
460 else if( id == 5011 || // MENU BOOLEAN - FUSE
461 id == 5012 || // MENU BOOLEAN - COMMON
462 id == 5013 || // MENU BOOLEAN - CUT
463 id == 5014 ) { // MENU BOOLEAN - SECTION
465 library = getLibrary( "libBooleanGUI.so" );
467 library = getLibrary( "BooleanGUI.dll" );
470 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
471 id == 5022 || // MENU TRANSFORMATION - ROTATION
472 id == 5023 || // MENU TRANSFORMATION - LOCATION
473 id == 5024 || // MENU TRANSFORMATION - MIRROR
474 id == 5025 || // MENU TRANSFORMATION - SCALE
475 id == 5026 || // MENU TRANSFORMATION - OFFSET
476 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
477 id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
479 library = getLibrary( "libTransformationGUI.so" );
481 library = getLibrary( "TransformationGUI.dll" );
484 else if( id == 503 || // MENU OPERATION - PARTITION
485 id == 504 || // MENU OPERATION - ARCHIMEDE
486 id == 505 || // MENU OPERATION - FILLET
487 id == 506 || // MENU OPERATION - CHAMFER
488 id == 507 ) { // MENU OPERATION - CLIPPING RANGE
490 library = getLibrary( "libOperationGUI.so" );
492 library = getLibrary( "OperationGUI.dll" );
495 else if( id == 601 || // MENU REPAIR - SEWING
496 id == 603 || // MENU REPAIR - SUPPRESS FACES
497 id == 604 || // MENU REPAIR - SUPPRESS HOLE
498 id == 605 || // MENU REPAIR - SHAPE PROCESSING
499 id == 606 || // MENU REPAIR - CLOSE CONTOUR
500 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
501 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
502 id == 609 || // MENU REPAIR - FREE BOUNDARIES
503 id == 610 || // MENU REPAIR - FREE FACES
504 id == 602 ) { // MENU REPAIR - GLUE FACES
506 library = getLibrary( "libRepairGUI.so" );
508 library = getLibrary( "RepairGUI.dll" );
511 else if( id == 701 || // MENU MEASURE - PROPERTIES
512 id == 702 || // MENU MEASURE - CDG
513 id == 703 || // MENU MEASURE - INERTIA
514 id == 7041 || // MENU MEASURE - BOUNDING BOX
515 id == 7042 || // MENU MEASURE - MIN DISTANCE
516 id == 705 || // MENU MEASURE - TOLERANCE
517 id == 706 || // MENU MEASURE - WHATIS
518 id == 707 || // MENU MEASURE - CHECK
519 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
520 id == 708 ) { // MENU MEASURE - POINT COORDINATES
522 library = getLibrary( "libMeasureGUI.so" );
524 library = getLibrary( "MeasureGUI.dll" );
527 else if( id == 800 || // MENU GROUP - CREATE
528 id == 8001 || // POPUP MENU - CREATE GROUP
529 id == 801 ) { // MENU GROUP - EDIT
531 library = getLibrary( "libGroupGUI.so" );
533 library = getLibrary( "GroupGUI.dll" );
536 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
537 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
538 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
539 id == 99991 || // MENU BLOCKS - PROPAGATE
540 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
542 library = getLibrary( "libBlocksGUI.so" );
544 library = getLibrary( "BlocksGUI.dll" );
548 // call method of corresponding GUI library
550 library->OnGUIEvent( id, desk );
552 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
556 //=================================================================================
557 // function : GeometryGUI::OnKeyPress()
558 // purpose : Called when any key is pressed by user [static]
559 //=================================================================================
560 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
564 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
565 bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
570 //=================================================================================
571 // function : GeometryGUI::OnMouseMove()
572 // purpose : Manages mouse move events [static]
573 //=================================================================================
574 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
578 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
579 bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
584 //=================================================================================
585 // function : GeometryGUI::0nMousePress()
586 // purpose : Manage mouse press events [static]
587 //=================================================================================
588 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
591 // OnMousePress() should return false if this event should be processed further
592 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
593 bool processed = false;
594 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
595 processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
600 static void UpdateVtkSelection()
602 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
603 SUIT_ViewWindow* win = 0;
604 for ( win = winList.first(); win; win = winList.next() ) {
605 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
606 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
608 SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
609 anInteractor->SetSelectionProp();
610 anInteractor->SetSelectionTolerance();
611 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
613 aStyle->setPreselectionProp();
620 //=================================================================================
621 // function : GeometryGUI::SetSettings()
622 // purpose : Called when GEOM module is activated [static]
623 //=================================================================================
624 bool GeometryGUI::SetSettings()
626 QMenuBar* Mb = parent->getMainMenuBar();
627 SUIT_Study* ActiveStudy = application()->activeStudy();
629 // Wireframe or Shading
631 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
632 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
633 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
635 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
637 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
638 DisplayMode = ic->DisplayMode();
641 else if ( ViewVTK ) {
642 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
644 SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
645 DisplayMode = myRenderInter->GetDisplayMode();
649 if( DisplayMode == 1 )
651 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
653 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
656 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
657 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
658 int Settings_AddInStudy;
659 // if(!AddInStudy.isEmpty())
660 // Settings_AddInStudy = AddInStudy.toInt();
663 Settings_AddInStudy = 1;
664 Mb->setItemChecked(411, Settings_AddInStudy);
667 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
669 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
672 int count = ActiveStudy->getStudyFramesCount();
673 for(int i = 0; i < count; i++) {
674 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
675 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
676 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
678 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
679 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
681 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
683 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
689 // PAL5356: update VTK selection
690 ::UpdateVtkSelection();
693 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
694 bOk = bOk && it.data()->SetSettings( parent );
696 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
697 if (getenv( "GEOM_CLIPPING" ) == NULL)
699 QMenuItem* mi = Mb->findItem(50);
700 if (mi && mi->popup())
701 mi->popup()->removeItem(507);
708 //=======================================================================
709 // function : createGeomAction
711 //=======================================================================
712 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
715 QWidget* parent = application()->desktop();
716 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
718 if ( icon_id.length() )
719 pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
721 pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
723 icon = QIconSet( pix );
725 QString tooltip = tr( QString( "TOP_" )+po_id ),
726 menu = tr( QString( "MEN_" )+po_id ),
727 status_bar = tr( QString( "STB_" )+po_id );
729 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
734 //=======================================================================
735 // function : GeometryGUI::Deactivate()
736 // purpose : Called when GEOM module is deactivated [ static ]
737 //=======================================================================
738 void GeometryGUI::initialize( CAM_Application* app )
740 SalomeApp_Module::initialize( app );
742 // ----- create actions --------------
744 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
745 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
747 createGeomAction( 33, "DELETE" );
749 createGeomAction( 4011, "POINT" );
750 createGeomAction( 4012, "LINE" );
751 createGeomAction( 4013, "CIRCLE" );
752 createGeomAction( 4014, "ELLIPSE" );
753 createGeomAction( 4015, "ARC" );
754 createGeomAction( 4019, "CURVE" );
755 createGeomAction( 4016, "VECTOR" );
756 createGeomAction( 4017, "PLANE" );
757 createGeomAction( 4018, "WORK_PLANE" );
758 createGeomAction( 4020, "LOCAL_CS" );
760 createGeomAction( 4021, "BOX" );
761 createGeomAction( 4022, "CYLINDER" );
762 createGeomAction( 4023, "SPHERE" );
763 createGeomAction( 4024, "TORUS" );
764 createGeomAction( 4025, "CONE" );
766 createGeomAction( 4031, "EXTRUSION" );
767 createGeomAction( 4032, "REVOLUTION" );
768 createGeomAction( 4033, "FILLING" );
769 createGeomAction( 4034, "PIPE" );
771 createGeomAction( 800, "GROUP_CREATE" );
772 createGeomAction( 801, "GROUP_EDIT" );
774 createGeomAction( 9997, "Q_FACE" );
775 createGeomAction( 9999, "HEX_SOLID" );
777 createGeomAction( 404, "SKETCH" );
778 createGeomAction( 407, "EXPLODE" );
780 createGeomAction( 4081, "EDGE" );
781 createGeomAction( 4082, "WIRE" );
782 createGeomAction( 4083, "FACE" );
783 createGeomAction( 4084, "SHELL" );
784 createGeomAction( 4085, "SOLID" );
785 createGeomAction( 4086, "COMPOUND" );
787 createGeomAction( 5011, "FUSE" );
788 createGeomAction( 5012, "COMMON" );
789 createGeomAction( 5013, "CUT" );
790 createGeomAction( 5014, "SECTION" );
792 createGeomAction( 5021, "TRANSLATION" );
793 createGeomAction( 5022, "ROTATION" );
794 createGeomAction( 5023, "MODIFY_LOCATION" );
795 createGeomAction( 5024, "MIRROR" );
796 createGeomAction( 5025, "SCALE" );
797 createGeomAction( 5026, "OFFSET" );
798 createGeomAction( 5027, "MUL_TRANSLATION" );
799 createGeomAction( 5028, "MUL_ROTATION" );
801 createGeomAction( 503, "PARTITION" );
802 createGeomAction( 504, "ARCHIMEDE" );
803 createGeomAction( 505, "FILLET" );
804 createGeomAction( 506, "CHAMFER" );
805 //createGeomAction( 507, "CLIPPING" );
807 createGeomAction( 9998, "MUL_TRANSFORM" );
808 createGeomAction( 9995, "EXPLODE_BLOCKS" );
809 createGeomAction( 99991, "PROPAGATE" );
811 createGeomAction( 601, "SEWING" );
812 createGeomAction( 602, "GLUE_FACES" );
813 createGeomAction( 603, "SUPPRESS_FACES" );
814 createGeomAction( 604, "SUPPERSS_HOLES" );
815 createGeomAction( 605, "SHAPE_PROCESS" );
816 createGeomAction( 606, "CLOSE_CONTOUR" );
817 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
818 createGeomAction( 608, "POINT_ON_EDGE" );
819 createGeomAction( 609, "CHECK_FREE_BNDS" );
820 createGeomAction( 610, "CHECK_FREE_FACES" );
822 createGeomAction( 708, "POINT_COORDS" );
823 createGeomAction( 701, "BASIC_PROPS" );
824 createGeomAction( 702, "MASS_CENTER" );
825 createGeomAction( 703, "INERTIA" );
826 createGeomAction( 7041, "BND_BOX" );
827 createGeomAction( 7042, "MIN_DIST" );
829 createGeomAction( 705, "TOLERANCE" );
830 createGeomAction( 706, "WHAT_IS" );
831 createGeomAction( 707, "CHECK" );
832 createGeomAction( 7072, "CHECK_COMPOUND" );
834 createGeomAction( 5103, "CHECK_GEOMETRY" );
836 createGeomAction( 412, "SHADING_COLOR" );
837 createGeomAction( 413, "ISOS" );
838 createGeomAction( 414, "STEP_VALUE" );
840 createGeomAction( 211, "SHADING" );
841 createGeomAction( 212, "DISPLAY_ALL" );
842 createGeomAction( 214, "ERASE_ALL" );
843 createGeomAction( 216, "DISPLAY" );
844 createGeomAction( 213, "DISPLAY_ONLY" );
845 createGeomAction( 215, "ERASE" );
847 createGeomAction( 901, "POP_RENAME" );
848 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
849 createGeomAction( 80312, "POP_SHADING", "", 0, true );
850 createGeomAction( 8032, "POP_COLOR" );
851 createGeomAction( 8033, "POP_TRANSPARENCY" );
852 createGeomAction( 8034, "POP_ISOS" );
853 createGeomAction( 8001, "POP_CREATE_GROUP" );
855 // make wireframe-shading items to be exclusive (only one at a time is selected)
856 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
857 //dispModeGr->add( action( 80311 ) );
858 //dispModeGr->add( action( 80312 ) );
859 // ---- create menu --------------------------
861 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
862 createMenu( separator(), fileId, 10 );
863 createMenu( 111, fileId, 10 );
864 createMenu( 121, fileId, 10 );
865 createMenu( separator(), fileId, -1 );
867 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
868 createMenu( 33, editId, -1 );
870 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
872 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
873 createMenu( 4011, basicId, -1 );
874 createMenu( 4012, basicId, -1 );
875 createMenu( 4013, basicId, -1 );
876 createMenu( 4014, basicId, -1 );
877 createMenu( 4015, basicId, -1 );
878 createMenu( 4019, basicId, -1 );
879 createMenu( separator(), basicId, -1 );
880 createMenu( 4016, basicId, -1 );
881 createMenu( 4017, basicId, -1 );
882 createMenu( 4018, basicId, -1 );
883 createMenu( 4020, basicId, -1 );
885 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
886 createMenu( 4021, primId, -1 );
887 createMenu( 4022, primId, -1 );
888 createMenu( 4023, primId, -1 );
889 createMenu( 4024, primId, -1 );
890 createMenu( 4025, primId, -1 );
892 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
893 createMenu( 4031, genId, -1 );
894 createMenu( 4032, genId, -1 );
895 createMenu( 4033, genId, -1 );
896 createMenu( 4034, genId, -1 );
897 createMenu( separator(), newEntId, -1 );
899 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
900 createMenu( 800, groupId, -1 );
901 createMenu( 801, groupId, -1 );
902 createMenu( separator(), newEntId, -1 );
904 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
905 createMenu( 9997, blocksId, -1 );
906 createMenu( 9999, blocksId, -1 );
908 createMenu( separator(), newEntId, -1 );
909 createMenu( 404, newEntId, -1 );
910 createMenu( separator(), newEntId, -1 );
911 createMenu( 407, newEntId, -1 );
913 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
914 createMenu( 4081, buildId, -1 );
915 createMenu( 4082, buildId, -1 );
916 createMenu( 4083, buildId, -1 );
917 createMenu( 4084, buildId, -1 );
918 createMenu( 4085, buildId, -1 );
919 createMenu( 4086, buildId, -1 );
921 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
923 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
924 createMenu( 5011, boolId, -1 );
925 createMenu( 5012, boolId, -1 );
926 createMenu( 5013, boolId, -1 );
927 createMenu( 5014, boolId, -1 );
929 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
930 createMenu( 5021, transId, -1 );
931 createMenu( 5022, transId, -1 );
932 createMenu( 5023, transId, -1 );
933 createMenu( 5024, transId, -1 );
934 createMenu( 5025, transId, -1 );
935 createMenu( 5026, transId, -1 );
936 createMenu( separator(), transId, -1 );
937 createMenu( 5027, transId, -1 );
938 createMenu( 5028, transId, -1 );
940 createMenu( 503, operId, -1 );
941 createMenu( 504, operId, -1 );
942 createMenu( separator(), operId, -1 );
943 createMenu( 505, transId, -1 );
944 createMenu( 506, transId, -1 );
945 //createMenu( 507, transId, -1 );
947 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
948 createMenu( 9998, blockId, -1 );
949 createMenu( 9995, blockId, -1 );
950 createMenu( 99991, blockId, -1 );
952 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
953 createMenu( 605, repairId, -1 );
954 createMenu( 603, repairId, -1 );
955 createMenu( 606, repairId, -1 );
956 createMenu( 607, repairId, -1 );
957 createMenu( 604, repairId, -1 );
958 createMenu( 601, repairId, -1 );
959 createMenu( 602, repairId, -1 );
960 createMenu( 608, repairId, -1 );
961 createMenu( 609, repairId, -1 );
962 createMenu( 610, repairId, -1 );
964 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
965 createMenu( 708, measurId, -1 );
966 createMenu( 701, measurId, -1 );
967 createMenu( separator(), measurId, -1 );
968 createMenu( 702, measurId, -1 );
969 createMenu( 703, measurId, -1 );
970 createMenu( separator(), measurId, -1 );
972 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
973 createMenu( 7041, dimId, -1 );
974 createMenu( 7042, dimId, -1 );
975 createMenu( separator(), measurId, -1 );
977 createMenu( 705, measurId, -1 );
978 createMenu( separator(), measurId, -1 );
979 createMenu( 706, measurId, -1 );
980 createMenu( 707, measurId, -1 );
981 createMenu( 7072, measurId, -1 );
983 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
984 createMenu( separator(), toolsId, -1 );
985 createMenu( 5103, toolsId, -1 );
987 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
988 //createMenu( separator(), prefId, -1 );
989 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
990 //createMenu( 412, geomId, -1 );
991 //createMenu( 413, geomId, -1 );
992 //createMenu( 414, geomId, -1 );
993 //createMenu( separator(), prefId, -1 );
995 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
996 createMenu( separator(), viewId, -1 );
998 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
999 createMenu( 211, dispmodeId, -1 );
1001 createMenu( separator(), viewId, -1 );
1002 createMenu( 212, viewId, -1 );
1003 createMenu( 214, viewId, -1 );
1004 createMenu( separator(), viewId, -1 );
1008 because of these items are accessible through object browser and viewers
1009 we have removed they from main menu
1011 createMenu( 216, viewId, -1 );
1012 createMenu( 213, viewId, -1 );
1013 createMenu( 215, viewId, -1 );
1016 // ---- create toolbars --------------------------
1018 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1019 createTool( 4011, basicTbId );
1020 createTool( 4012, basicTbId );
1021 createTool( 4013, basicTbId );
1022 createTool( 4014, basicTbId );
1023 createTool( 4015, basicTbId );
1024 createTool( 4019, basicTbId );
1025 createTool( 4016, basicTbId );
1026 createTool( 4017, basicTbId );
1027 createTool( 4018, basicTbId );
1028 createTool( 4020, basicTbId );
1030 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1031 createTool( 4021, primTbId );
1032 createTool( 4022, primTbId );
1033 createTool( 4023, primTbId );
1034 createTool( 4024, primTbId );
1035 createTool( 4025, primTbId );
1037 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1038 createTool( 5011, boolTbId );
1039 createTool( 5012, boolTbId );
1040 createTool( 5013, boolTbId );
1041 createTool( 5014, boolTbId );
1043 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1044 createTool( 4031, genTbId );
1045 createTool( 4032, genTbId );
1046 createTool( 4033, genTbId );
1047 createTool( 4034, genTbId );
1049 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1050 createTool( 5021, transTbId );
1051 createTool( 5022, transTbId );
1052 createTool( 5023, transTbId );
1053 createTool( 5024, transTbId );
1054 createTool( 5025, transTbId );
1055 createTool( 5026, transTbId );
1056 createTool( separator(), transTbId );
1057 createTool( 5027, transTbId );
1058 createTool( 5028, transTbId );
1060 QtxPopupMgr* mgr = popupMgr();
1061 mgr->insert( action( 901 ), -1, -1 ); // rename
1062 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1063 mgr->insert( action( 8001 ), -1, -1 ); // create group
1064 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1065 mgr->insert( action( 801 ), -1, -1 ); // edit group
1066 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1067 mgr->insert( separator(), -1, -1 ); // -----------
1068 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1069 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1070 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1071 mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Wireframe'", false );
1072 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1073 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1074 mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Shading'", false );
1075 mgr->insert( separator(), -1, -1 ); // -----------
1076 mgr->insert( action( 8032 ), -1, -1 ); // color
1077 mgr->setRule( action( 8032 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1078 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1079 mgr->setRule( action( 8033 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0 and isVisible", true );
1080 mgr->insert( action( 8034 ), -1, -1 ); // isos
1081 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true );
1082 mgr->insert( separator(), -1, -1 ); // -----------
1086 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1087 onlyComponent = "((type='Component') and selcount=1)",
1088 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1089 types = "'Shape' 'Group'";
1091 mgr->insert( action( 216 ), -1, -1 ); // display
1092 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), true );
1094 mgr->insert( action( 215 ), -1, -1 ); // erase
1095 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), true );
1097 mgr->insert( action( 214 ), -1, -1 ); // erase All
1098 mgr->setRule( action( 214 ), "client='OCCViewer' or client='VTKViewer'", true );
1100 mgr->insert( action( 213 ), -1, -1 ); // display only
1101 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), true );
1102 mgr->insert( separator(), -1, -1 );
1104 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1107 //=======================================================================
1108 // function : GeometryGUI::Deactivate()
1109 // purpose : Called when GEOM module is deactivated [ static ]
1110 //=======================================================================
1111 bool GeometryGUI::activateModule( SUIT_Study* study )
1113 if ( CORBA::is_nil( myComponentGeom ) )
1116 bool res = SalomeApp_Module::activateModule( study );
1121 setMenuShown( true );
1122 setToolShown( true );
1124 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1125 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1127 GUIMap::Iterator it;
1128 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1129 it.data()->activate( application()->desktop() );
1131 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1132 SUIT_ViewManager* vm;
1133 ViewManagerList OCCViewManagers, VTKViewManagers;
1134 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1135 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1136 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1137 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1138 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1139 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1141 // disable OCC selectors
1142 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1143 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1144 sr->setEnabled(true);
1146 // disable VTK selectors
1147 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1148 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1149 sr->setEnabled(true);
1155 //=======================================================================
1156 // function : GeometryGUI::Deactivate()
1157 // purpose : Called when GEOM module is deactivated [ static ]
1158 //=======================================================================
1159 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1161 setMenuShown( false );
1162 setToolShown( false );
1164 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1165 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1167 EmitSignalCloseAllDialogs();
1169 GUIMap::Iterator it;
1170 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1171 it.data()->deactivate();
1173 myOCCSelectors.clear();
1174 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1176 myVTKSelectors.clear();
1177 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1179 return SalomeApp_Module::deactivateModule( study );
1182 //=================================================================================
1183 // function : GeometryGUI::DefinePopup()
1184 // purpose : Called from desktop to define popup menu [static]
1185 //=================================================================================
1187 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1189 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1190 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1195 if ( theParent == "Viewer" ) {
1196 if ( Sel->IObjectCount() == 0 )
1197 theContext = "NothingSelected";
1200 if ( Sel->IObjectCount() == 1 ) {
1201 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1202 if( IO->hasEntry() ) {
1203 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1204 if ( !sobj->_is_nil() ) {
1205 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1206 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1207 // component is selected
1208 theObject = "Component";
1211 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1212 if ( !CORBA::is_nil( aGObj ) ) {
1213 switch( aGObj->GetType() ) {
1215 theObject = "Group";
1218 theObject = "Shape";
1228 //=================================================================================
1229 // function : GeometryGUI::CustomPopup()
1230 // purpose : Called from desktop to create popup menu [static]
1231 //=================================================================================
1232 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1233 const QString& theParent, const QString& theObject)
1235 GeometryGUI* geomGUI = GetGeomGUI();
1237 // Deactivate any non modal dialog box to get the neutral point
1238 geomGUI->EmitSignalDeactivateDialog();
1239 QAD_Study* anActiveStudy = parent->getActiveStudy();
1240 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1241 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1242 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1243 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1244 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1245 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1246 int aDisplayMode = 0;
1249 if ( aViewFrame->getTypeView() == VIEW_OCC )
1250 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1251 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1252 aDisplayMode = (dynamic_cast<SVTK_ViewFrame*>( aViewFrame )->getRWInteractor()->GetDisplayMode();
1254 int nbSel = Sel->IObjectCount();
1257 ////// NOTHING SELECTED
1260 else if ( nbSel == 1 ) {
1261 ////// SINGLE OBJECT SELECTION
1262 if ( parentComponent != parent->getActiveComponent() ) {
1263 ////// selected object does not belong to GEOM module:
1264 // remove all commands except Display/Erase...
1266 int id = popup->idAt( 0 );
1267 if ( id <= QAD_TopLabel_Popup_ID )
1268 popup->removeItemAt( 0 );
1274 ////// selected object belong to the GEOM module
1275 // get interactive object
1276 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1277 objectName = IObject->getName();
1278 // if object has entry get SObject
1279 SALOMEDS::SObject_var SO;
1280 if ( IObject->hasEntry() )
1281 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1283 if ( theObject == "Component" ) {
1284 ////// menu for component
1285 if ( !isOCCViewer && !isVTKViewer ) {
1286 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1287 popup->removeItem( QAD_Display_Popup_ID );
1288 popup->removeItem( QAD_Erase_Popup_ID );
1292 ////// not component (should be shape)
1293 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1294 popup->removeItem( 804 ); // "Add in Study"
1296 // Here could be analysis of the geom shape's type
1299 SALOMEDS::GenericAttribute_var aTmpAttr;
1300 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1301 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1303 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1304 if ( theObject == "Shape" )
1305 popup->removeItem( 800 ); // Create Group
1306 else if ( theObject == "Group" )
1307 popup->removeItem( 801 ); // Edit Group
1310 if ( isOCCViewer || isVTKViewer ) {
1311 ////// current viewer is OCC or VTK
1312 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1313 if ( aViewFrame->isVisible( IObject ) ) {
1314 ////// object is already displayed in the viewer
1315 popup->removeItem( QAD_Display_Popup_ID );
1316 if ( isOCCViewer ) {
1317 ////// OCC viewer only
1318 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1319 if ( occPrs && !occPrs->IsNull() ) {
1320 AIS_ListOfInteractive ioList;
1321 occPrs->GetObjects( ioList );
1322 QMenuItem* mi = popup->findItem( 803 );
1323 if ( mi && mi->popup() ) {
1324 if ( ioList.First()->DisplayMode() == 0 )
1325 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1326 else if ( ioList.First()->DisplayMode() == 1 )
1327 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1328 else if ( ioList.First()->DisplayMode() < 0 )
1329 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1334 ////// VTK viewer only
1335 popup->removeItem( 8034 ); // "Isos"
1336 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1337 if ( vtkPrs && !vtkPrs->IsNull() ) {
1338 vtkActorCollection* actorList = vtkPrs->GetObjects();
1339 actorList->InitTraversal();
1340 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1341 QMenuItem* mi = popup->findItem( 803 );
1342 if ( ac && mi && mi->popup() ) {
1343 if ( ac->getDisplayMode() == 0 )
1344 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1345 else if ( ac->getDisplayMode() == 1 )
1346 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1348 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1354 ////// object is not yet displayed in the viewer
1355 popup->removeItem( 803 ); // "Display Mode"
1356 popup->removeItem( 8032 ); // "Color"
1357 popup->removeItem( 8033 ); // "Transparency"
1358 popup->removeItem( 8034 ); // "Isos"
1359 popup->removeItem( QAD_Erase_Popup_ID );
1364 ////// other viewer type (neither OCC nor VTK)
1365 popup->removeItem( 803 ); // "Display Mode"
1366 popup->removeItem( 8032 ); // "Color"
1367 popup->removeItem( 8033 ); // "Transparency"
1368 popup->removeItem( 8034 ); // "Isos"
1369 popup->removeItem( QAD_Display_Popup_ID );
1370 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1371 popup->removeItem( QAD_Erase_Popup_ID );
1377 ////// MULTIPLE SELECTION
1378 if ( parentComponent != parent->getActiveComponent() ) {
1379 ////// not GEOM module objects or objects belong to different modules
1380 // remove all commands except Display/Erase...
1382 int id = popup->idAt( 0 );
1383 if ( id <= QAD_TopLabel_Popup_ID )
1384 popup->removeItemAt( 0 );
1388 if ( parentComponent.isNull() ) {
1389 ////// objects belong to different modules
1390 popup->removeItem(QAD_Display_Popup_ID);
1391 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1392 popup->removeItem(QAD_Erase_Popup_ID);
1395 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1399 ////// all selected objects belong to GEOM module
1400 popup->removeItem( 901 ); // "Rename"
1402 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1403 bool isComponent = false;
1404 bool needOpen = false;
1405 bool needDisplay = false;
1406 bool needErase = false;
1407 int needToPublish = 0;
1409 for( ;It.More();It.Next() ) {
1410 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1412 if ( aViewFrame->isVisible( anIObject ) )
1417 if( anIObject->hasEntry() ) {
1418 needToPublish = -1; /////// VSR : TO BE REMOVED
1419 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1420 SALOMEDS::GenericAttribute_var aTmpAttr;
1421 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1422 needOpen = true; /////// VSR : TO BE REMOVED
1423 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1427 if ( needToPublish != -1 ) needToPublish = 1;
1430 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1431 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1432 popup->removeItem( 803 ); // "Display Mode"
1433 popup->removeItem( 8032 ); // "Color"
1434 popup->removeItem( 8033 ); // "Transparency"
1435 popup->removeItem( 8034 ); // "Isos"
1436 popup->removeItem( 804 ); // "Add in Study"
1437 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1438 popup->removeItem( QAD_Display_Popup_ID );
1439 popup->removeItem( QAD_Erase_Popup_ID );
1442 popup->removeItem( 9024 ); // "Open"
1443 if ( needToPublish <= 0 )
1444 popup->removeItem( 804 ); // "Add in Study"
1447 popup->removeItem( 803 ); // "Display Mode"
1448 popup->removeItem( 8032 ); // "Color"
1449 popup->removeItem( 8033 ); // "Transparency"
1450 popup->removeItem( 8034 ); // "Isos"
1451 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1455 popup->removeItem( QAD_Display_Popup_ID );
1457 popup->removeItem( QAD_Erase_Popup_ID );
1459 popup->removeItem( 8034 ); // "Isos"
1464 // check popup for unnecessary separators
1465 QAD_Tools::checkPopup( popup );
1466 // find popup menu's TopLabel item (with title)
1467 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1468 if ( topItem >= 0 ) {
1469 // remove popup menu's title item
1470 popup->removeItem( QAD_TopLabel_Popup_ID );
1471 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1472 // set bold font for popup menu's title
1473 QFont f = popup->font(); f.setBold( TRUE );
1474 popup->removeItem( QAD_TopLabel_Popup_ID );
1475 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1484 //=======================================================================
1485 // function : GeometryGUI::BuildPresentation()
1487 //=======================================================================
1488 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1490 //GEOM_Displayer().Display( io, false, win );
1493 //=======================================================================
1494 // function : setCommandsEnabled()
1495 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1496 //=======================================================================
1497 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1502 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1503 // const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1505 // disable non-OCC viewframe menu commands
1506 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1507 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1508 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1509 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1510 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1511 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1512 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1513 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1515 action( 800 )->setEnabled( ViewOCC ); // Create Group
1516 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1518 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1521 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1523 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1524 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1527 void GeometryGUI::viewManagers( QStringList& lst ) const
1529 lst.append( OCCViewer_Viewer::Type() );
1532 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1534 if ( vm->getType() == OCCViewer_Viewer::Type() )
1536 qDebug( "connect" );
1537 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1538 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1539 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1540 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1541 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1542 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1545 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1546 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1548 // disable OCC selectors
1549 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1550 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1551 sr->setEnabled(true);
1553 else if ( vm->getType() == SVTK_Viewer::Type() )
1555 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1556 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1558 // disable VTK selectors
1559 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1560 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1561 sr->setEnabled(true);
1565 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1567 SUIT_ViewModel* viewer = vm->getViewModel();
1568 if ( vm->getType() == OCCViewer_Viewer::Type() )
1570 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1571 if ( sr->viewer() == viewer )
1573 myOCCSelectors.remove( sr );
1577 if ( vm->getType() == SVTK_Viewer::Type() )
1579 for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1580 if ( sr->viewer() == viewer )
1582 myVTKSelectors.remove( sr );
1588 QString GeometryGUI::engineIOR() const
1590 if ( !CORBA::is_nil( GetGeomGen() ) )
1591 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1592 return QString( "" );
1595 LightApp_Selection* GeometryGUI::createSelection() const
1597 return new GEOMGUI_Selection();
1600 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1602 SalomeApp_Module::contextMenuPopup( client, menu, title );
1604 getApp()->selectionMgr()->selectedObjects( lst );
1605 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1606 Handle(SALOME_InteractiveObject) io = lst.First();
1607 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1608 _PTR(Study) study = appStudy->studyDS();
1609 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1611 title = QString( obj->GetName().c_str() );
1615 void GeometryGUI::createPreferences()
1617 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1619 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1620 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1621 LightApp_Preferences::Color, "Geometry", "shading_color" );
1622 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1623 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1624 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1625 LightApp_Preferences::Selector, "Geometry", "display_mode" );
1627 setPreferenceProperty( genGroup, "columns", 1 );
1629 setPreferenceProperty( step, "min", 0.001 );
1630 setPreferenceProperty( step, "max", 10000 );
1631 setPreferenceProperty( step, "precision", 3 );
1633 // Set property for default display mode
1634 QStringList aModesList;
1635 aModesList.append( tr("MEN_WIREFRAME") );
1636 aModesList.append( tr("MEN_SHADING") );
1638 QValueList<QVariant> anIndexesList;
1639 anIndexesList.append(0);
1640 anIndexesList.append(1);
1642 setPreferenceProperty( dispmode, "strings", aModesList );
1643 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1646 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1650 LightApp_Displayer* GeometryGUI::displayer()
1653 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );