1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GeometryGUI.h"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ViewManager.h>
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
43 #include <VTKViewer_ViewWindow.h>
44 #include <SVTK_RenderWindowInteractor.h>
45 #include <SVTK_InteractorStyle.h>
46 #include <SVTK_ViewModel.h>
47 #include <VTKViewer_ViewManager.h>
49 #include <SalomeApp_Application.h>
50 #include <SalomeApp_SelectionMgr.h>
51 #include <SalomeApp_VTKSelector.h>
52 #include <SalomeApp_Study.h>
53 #include <SalomeApp_Preferences.h>
54 #include <SALOME_LifeCycleCORBA.hxx>
55 #include <SALOME_ListIO.hxx>
58 #include <qfileinfo.h>
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <OSD_SharedLibrary.hxx>
65 #include <utilities.h>
67 #include <vtkCamera.h>
68 #include <vtkRenderer.h>
71 Standard_EXPORT CAM_Module* createModule() {
72 return new GeometryGUI();
76 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
78 bool GeometryGUI::InitGeomGen()
81 if( CORBA::is_nil( myComponentGeom ) ) return false;
85 //=================================================================================
87 // purpose : Set Font to a text.
88 //=================================================================================
89 class CustomItem : public QCustomMenuItem
92 CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
95 void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
98 p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
99 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
100 p->setFont( myFont );
101 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
107 return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
110 bool fullSpan() const
120 //=======================================================================
121 // function : GeometryGUI::GeometryGUI()
122 // purpose : Constructor
123 //=======================================================================
124 GeometryGUI::GeometryGUI() :
125 SalomeApp_Module( "GEOM" )
127 if ( CORBA::is_nil( myComponentGeom ) )
129 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
130 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
131 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
135 myActiveDialogBox = 0;
138 gp_Pnt origin = gp_Pnt(0., 0., 0.);
139 gp_Dir direction = gp_Dir(0., 0., 1.);
140 myWorkingPlane = gp_Ax3(origin, direction);
142 myOCCSelectors.setAutoDelete( true );
143 myVTKSelectors.setAutoDelete( true );
146 //=======================================================================
147 // function : GeometryGUI::~GeometryGUI()
148 // purpose : Destructor
149 //=======================================================================
150 GeometryGUI::~GeometryGUI()
154 //=======================================================================
155 // function : GeometryGUI::getLibrary()
156 // purpose : get or load GUI library by name [ internal ]
157 //=======================================================================
158 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
159 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
161 if ( !myGUIMap.contains( libraryName ) ) {
162 // try to load library if it is not loaded yet
164 if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
165 QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
166 for( int i = dirList.count()-1; i >= 0; i-- ) {
167 QString dir = dirList[ i ];
168 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
170 OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
171 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
173 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
174 continue; // continue search further
176 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
177 if ( osdF != NULL ) {
178 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
179 GEOMGUI* libGUI = (*func)(this);
181 myGUIMap[ libraryName ] = libGUI;
182 break; // found and loaded!
189 if ( myGUIMap.contains( libraryName ) )
190 // library is successfully loaded
191 return myGUIMap[ libraryName ];
195 //=======================================================================
196 // function : GeometryGUI::ActiveWorkingPlane()
197 // purpose : Activate Working Plane View
198 //=======================================================================
199 void GeometryGUI::ActiveWorkingPlane()
201 gp_Dir DZ = myWorkingPlane.Direction();
202 gp_Dir DY = myWorkingPlane.YDirection();
204 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
205 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
206 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
209 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
211 Handle(V3d_View) view3d = vw->getViewPort()->getView();
213 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
214 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
220 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
222 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
224 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
225 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
226 camera->SetFocalPoint(0,0,0);
233 //=======================================================================
234 // function : GeometryGUI::SetActiveDialogBox()
235 // purpose : Set active dialog box
236 //=======================================================================
237 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
239 myActiveDialogBox = (QDialog*)aDlg;
242 //=======================================================================
243 // function : GeometryGUI::EmitSignalDeactivateDialog()
244 // purpose : Emit a signal to deactivate the active dialog Box
245 //=======================================================================
246 void GeometryGUI::EmitSignalDeactivateDialog()
248 emit SignalDeactivateActiveDialog();
251 //=======================================================================
252 // function : GeometryGUI::EmitSignalCloseAllDialogs()
253 // purpose : Emit a signal to close all non modal dialogs box
254 //=======================================================================
255 void GeometryGUI::EmitSignalCloseAllDialogs()
257 emit SignalCloseAllDialogs();
260 //=======================================================================
261 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
262 // purpose : Emit a signal to inform that default real spin box step has
264 //=======================================================================
265 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
267 emit SignalDefaultStepValueChanged(newVal);
270 //=======================================================================
271 // function : GeometryGUI::OnGUIEvent()
272 // purpose : common slot for all menu/toolbar actions
273 //=======================================================================
274 void GeometryGUI::OnGUIEvent()
276 const QObject* obj = sender();
277 if ( !obj || !obj->inherits( "QAction" ) )
279 int id = actionId((QAction*)obj);
284 //=======================================================================
285 // function : GeometryGUI::OnGUIEvent()
286 // purpose : manage all events on GUI [static]
287 //=======================================================================
288 void GeometryGUI::OnGUIEvent( int id )
290 SUIT_Desktop* desk = application()->desktop();
292 // check type of the active viewframe
293 SUIT_ViewWindow* window = desk->activeWindow();
294 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
295 bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
296 // if current viewframe is not of OCC and not of VTK type - return immediately
297 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
298 bool NotViewerDependentCommand = ( id == 901 );
299 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
302 // fix for IPAL9103, point 2
303 if ( CORBA::is_nil( GetGeomGen() ) ) {
304 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
308 GEOMGUI* library = 0;
309 // try to get-or-load corresponding GUI library
310 if( id == 111 || // MENU FILE - IMPORT BREP
311 id == 112 || // MENU FILE - IMPORT IGES
312 id == 113 || // MENU FILE - IMPORT STEP
313 id == 121 || // MENU FILE - EXPORT BREP
314 id == 122 || // MENU FILE - EXPORT IGES
315 id == 123 || // MENU FILE - EXPORT STEP
316 id == 31 || // MENU EDIT - COPY
317 id == 33 || // MENU EDIT - DELETE
318 id == 411 || // MENU SETTINGS - ADD IN STUDY
319 id == 412 || // MENU SETTINGS - SHADING COLOR
320 id == 413 || // MENU SETTINGS - ISOS
321 id == 414 || // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
322 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
323 id == 8032 || // POPUP VIEWER - COLOR
324 id == 8033 || // POPUP VIEWER - TRANSPARENCY
325 id == 8034 || // POPUP VIEWER - ISOS
326 id == 804 || // POPUP VIEWER - ADD IN STUDY
327 id == 901 || // OBJECT BROWSER - RENAME
328 id == 9024 ) { // OBJECT BROWSER - OPEN
329 //cout << "id " << id << " received" << endl;
330 library = getLibrary( "libGEOMToolsGUI.so" );
332 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
333 id == 212 || // MENU VIEW - DISPLAY ALL
334 id == 213 || // MENU VIEW - DISPLAY ONLY
335 id == 214 || // MENU VIEW - ERASE ALL
336 id == 215 || // MENU VIEW - ERASE
337 id == 216 || // MENU VIEW - DISPLAY
338 id == 80311 || // POPUP VIEWER - WIREFRAME
339 id == 80312 ) { // POPUP VIEWER - SHADING
340 library = getLibrary( "libDisplayGUI.so" );
342 else if( id == 4011 || // MENU BASIC - POINT
343 id == 4012 || // MENU BASIC - LINE
344 id == 4013 || // MENU BASIC - CIRCLE
345 id == 4014 || // MENU BASIC - ELLIPSE
346 id == 4015 || // MENU BASIC - ARC
347 id == 4016 || // MENU BASIC - VECTOR
348 id == 4017 || // MENU BASIC - PLANE
349 id == 4018 || // MENU BASIC - WPLANE
350 id == 4019 || // MENU BASIC - CURVE
351 id == 4020 ) { // MENU BASIC - REPAIR
352 library = getLibrary( "libBasicGUI.so" );
354 else if( id == 4021 || // MENU PRIMITIVE - BOX
355 id == 4022 || // MENU PRIMITIVE - CYLINDER
356 id == 4023 || // MENU PRIMITIVE - SPHERE
357 id == 4024 || // MENU PRIMITIVE - TORUS
358 id == 4025 ) { // MENU PRIMITIVE - CONE
359 library = getLibrary( "libPrimitiveGUI.so" );
361 else if( id == 4031 || // MENU GENERATION - PRISM
362 id == 4032 || // MENU GENERATION - REVOLUTION
363 id == 4033 || // MENU GENERATION - FILLING
364 id == 4034 ) { // MENU GENERATION - PIPE
365 library = getLibrary( "libGenerationGUI.so" );
367 else if( id == 404 || // MENU ENTITY - SKETCHER
368 id == 407 ) { // MENU ENTITY - EXPLODE
369 library = getLibrary( "libEntityGUI.so" );
371 else if( id == 4081 || // MENU BUILD - EDGE
372 id == 4082 || // MENU BUILD - WIRE
373 id == 4083 || // MENU BUILD - FACE
374 id == 4084 || // MENU BUILD - SHELL
375 id == 4085 || // MENU BUILD - SOLID
376 id == 4086 ) { // MENU BUILD - COMPUND
377 library = getLibrary( "libBuildGUI.so" );
379 else if( id == 5011 || // MENU BOOLEAN - FUSE
380 id == 5012 || // MENU BOOLEAN - COMMON
381 id == 5013 || // MENU BOOLEAN - CUT
382 id == 5014 ) { // MENU BOOLEAN - SECTION
383 library = getLibrary( "libBooleanGUI.so" );
385 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
386 id == 5022 || // MENU TRANSFORMATION - ROTATION
387 id == 5023 || // MENU TRANSFORMATION - LOCATION
388 id == 5024 || // MENU TRANSFORMATION - MIRROR
389 id == 5025 || // MENU TRANSFORMATION - SCALE
390 id == 5026 || // MENU TRANSFORMATION - OFFSET
391 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
392 id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
393 library = getLibrary( "libTransformationGUI.so" );
395 else if( id == 503 || // MENU OPERATION - PARTITION
396 id == 504 || // MENU OPERATION - ARCHIMEDE
397 id == 505 || // MENU OPERATION - FILLET
398 id == 506 || // MENU OPERATION - CHAMFER
399 id == 507 ) { // MENU OPERATION - CLIPPING RANGE
400 library = getLibrary( "libOperationGUI.so" );
402 else if( id == 601 || // MENU REPAIR - SEWING
403 id == 603 || // MENU REPAIR - SUPPRESS FACES
404 id == 604 || // MENU REPAIR - SUPPRESS HOLE
405 id == 605 || // MENU REPAIR - SHAPE PROCESSING
406 id == 606 || // MENU REPAIR - CLOSE CONTOUR
407 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
408 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
409 id == 609 || // MENU REPAIR - FREE BOUNDARIES
410 id == 610 || // MENU REPAIR - FREE FACES
411 id == 602 ) { // MENU REPAIR - GLUE FACES
412 library = getLibrary( "libRepairGUI.so" );
414 else if( id == 701 || // MENU MEASURE - PROPERTIES
415 id == 702 || // MENU MEASURE - CDG
416 id == 703 || // MENU MEASURE - INERTIA
417 id == 7041 || // MENU MEASURE - BOUNDING BOX
418 id == 7042 || // MENU MEASURE - MIN DISTANCE
419 id == 705 || // MENU MEASURE - TOLERANCE
420 id == 706 || // MENU MEASURE - WHATIS
421 id == 707 || // MENU MEASURE - CHECK
422 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
423 id == 708 ) { // MENU MEASURE - POINT COORDINATES
424 library = getLibrary( "libMeasureGUI.so" );
426 else if( id == 800 || // MENU GROUP - CREATE
427 id == 8001 || // POPUP MENU - CREATE GROUP
428 id == 801 ) { // MENU GROUP - EDIT
429 library = getLibrary( "libGroupGUI.so" );
431 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
432 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
433 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
434 id == 99991 || // MENU BLOCKS - PROPAGATE
435 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
436 library = getLibrary( "libBlocksGUI.so" );
439 // call method of corresponding GUI library
441 library->OnGUIEvent( id, desk );
443 SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
447 //=================================================================================
448 // function : GeometryGUI::OnKeyPress()
449 // purpose : Called when any key is pressed by user [static]
450 //=================================================================================
451 bool GeometryGUI::OnKeyPress( QKeyEvent* pe, SUIT_ViewWindow* win )
455 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
456 bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
461 //=================================================================================
462 // function : GeometryGUI::OnMouseMove()
463 // purpose : Manages mouse move events [static]
464 //=================================================================================
465 bool GeometryGUI::OnMouseMove( QMouseEvent* pe, SUIT_ViewWindow* win )
469 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
470 bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
475 //=================================================================================
476 // function : GeometryGUI::0nMousePress()
477 // purpose : Manage mouse press events [static]
478 //=================================================================================
479 bool GeometryGUI::OnMousePress( QMouseEvent* pe, SUIT_ViewWindow* win )
482 // OnMousePress() should return false if this event should be processed further
483 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
484 bool processed = false;
485 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
486 processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
491 static void UpdateVtkSelection()
493 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
494 SUIT_ViewWindow* win = 0;
495 for ( win = winList.first(); win; win = winList.next() ) {
496 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
497 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
499 VTKViewer_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
500 anInteractor->SetSelectionProp();
501 anInteractor->SetSelectionTolerance();
502 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
504 aStyle->setPreselectionProp();
511 //=================================================================================
512 // function : GeometryGUI::SetSettings()
513 // purpose : Called when GEOM module is activated [static]
514 //=================================================================================
515 bool GeometryGUI::SetSettings()
517 QMenuBar* Mb = parent->getMainMenuBar();
518 SUIT_Study* ActiveStudy = application()->activeStudy();
520 // Wireframe or Shading
522 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
523 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
524 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
526 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
528 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
529 DisplayMode = ic->DisplayMode();
532 else if ( ViewVTK ) {
533 VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
535 VTKViewer_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
536 DisplayMode = myRenderInter->GetDisplayMode();
540 if( DisplayMode == 1 )
542 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
544 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
547 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
548 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
549 int Settings_AddInStudy;
550 // if(!AddInStudy.isEmpty())
551 // Settings_AddInStudy = AddInStudy.toInt();
554 Settings_AddInStudy = 1;
555 Mb->setItemChecked(411, Settings_AddInStudy);
558 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
560 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
563 int count = ActiveStudy->getStudyFramesCount();
564 for(int i = 0; i < count; i++) {
565 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
566 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
567 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
569 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
570 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
572 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
574 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
580 // PAL5356: update VTK selection
581 ::UpdateVtkSelection();
584 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
585 bOk = bOk && it.data()->SetSettings( parent );
587 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
588 if (getenv( "GEOM_CLIPPING" ) == NULL)
590 QMenuItem* mi = Mb->findItem(50);
591 if (mi && mi->popup())
592 mi->popup()->removeItem(507);
599 //=======================================================================
600 // function : createGeomAction
602 //=======================================================================
603 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
606 QWidget* parent = application()->desktop();
607 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
609 if ( icon_id.length() )
610 pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
612 pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ) );
614 icon = QIconSet( pix );
616 QString tooltip = tr( QString( "TOP_" )+po_id ),
617 menu = tr( QString( "MEN_" )+po_id ),
618 status_bar = tr( QString( "STB_" )+po_id );
620 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
625 //=======================================================================
626 // function : GeometryGUI::Deactivate()
627 // purpose : Called when GEOM module is deactivated [ static ]
628 //=======================================================================
629 void GeometryGUI::initialize( CAM_Application* app )
631 SalomeApp_Module::initialize( app );
633 // ----- create actions --------------
635 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
636 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
638 createGeomAction( 33, "DELETE" );
640 createGeomAction( 4011, "POINT" );
641 createGeomAction( 4012, "LINE" );
642 createGeomAction( 4013, "CIRCLE" );
643 createGeomAction( 4014, "ELLIPSE" );
644 createGeomAction( 4015, "ARC" );
645 createGeomAction( 4019, "CURVE" );
646 createGeomAction( 4016, "VECTOR" );
647 createGeomAction( 4017, "PLANE" );
648 createGeomAction( 4018, "WORK_PLANE" );
649 createGeomAction( 4020, "LOCAL_CS" );
651 createGeomAction( 4021, "BOX" );
652 createGeomAction( 4022, "CYLINDER" );
653 createGeomAction( 4023, "SPHERE" );
654 createGeomAction( 4024, "TORUS" );
655 createGeomAction( 4025, "CONE" );
657 createGeomAction( 4031, "EXTRUSION" );
658 createGeomAction( 4032, "REVOLUTION" );
659 createGeomAction( 4033, "FILLING" );
660 createGeomAction( 4034, "PIPE" );
662 createGeomAction( 800, "GROUP_CREATE" );
663 createGeomAction( 801, "GROUP_EDIT" );
665 createGeomAction( 9997, "Q_FACE" );
666 createGeomAction( 9999, "HEX_SOLID" );
668 createGeomAction( 404, "SKETCH" );
669 createGeomAction( 407, "EXPLODE" );
671 createGeomAction( 4081, "EDGE" );
672 createGeomAction( 4082, "WIRE" );
673 createGeomAction( 4083, "FACE" );
674 createGeomAction( 4084, "SHELL" );
675 createGeomAction( 4085, "SOLID" );
676 createGeomAction( 4086, "COMPOUND" );
678 createGeomAction( 5011, "FUSE" );
679 createGeomAction( 5012, "COMMON" );
680 createGeomAction( 5013, "CUT" );
681 createGeomAction( 50114, "SECTION" );
683 createGeomAction( 5021, "TRANSLATION" );
684 createGeomAction( 5022, "ROTATION" );
685 createGeomAction( 5023, "MODIFY_LOCATION" );
686 createGeomAction( 5024, "MIRROR" );
687 createGeomAction( 5025, "SCALE" );
688 createGeomAction( 5026, "OFFSET" );
689 createGeomAction( 5027, "MUL_TRANSLATION" );
690 createGeomAction( 5028, "MUL_ROTATION" );
692 createGeomAction( 503, "PARTITION" );
693 createGeomAction( 504, "ARCHIMEDE" );
694 createGeomAction( 505, "FILLET" );
695 createGeomAction( 506, "CHAMFER" );
696 //createGeomAction( 507, "CLIPPING" );
698 createGeomAction( 9998, "MUL_TRANSFORM" );
699 createGeomAction( 9995, "EXPLODE_BLOCKS" );
700 createGeomAction( 99991, "PROPAGATE" );
702 createGeomAction( 601, "SEWING" );
703 createGeomAction( 602, "GLUE_FACES" );
704 createGeomAction( 603, "SUPPRESS_FACES" );
705 createGeomAction( 604, "SUPPERSS_HOLES" );
706 createGeomAction( 605, "SHAPE_PROCESS" );
707 createGeomAction( 606, "CLOSE_CONTOUR" );
708 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
709 createGeomAction( 608, "POINT_ON_EDGE" );
710 createGeomAction( 609, "CHECK_FREE_BNDS" );
711 createGeomAction( 610, "CHECK_FREE_FACES" );
713 createGeomAction( 708, "POINT_COORDS" );
714 createGeomAction( 701, "BASIC_PROPS" );
715 createGeomAction( 702, "MASS_CENTER" );
716 createGeomAction( 703, "INERTIA" );
717 createGeomAction( 7041, "BND_BOX" );
718 createGeomAction( 7042, "MIN_DIST" );
720 createGeomAction( 705, "TOLERANCE" );
721 createGeomAction( 706, "WHAT_IS" );
722 createGeomAction( 707, "CHECK" );
723 createGeomAction( 7072, "CHECK_COMPOUND" );
725 createGeomAction( 5103, "CHECK_GEOMETRY" );
727 createGeomAction( 412, "SHADING_COLOR" );
728 createGeomAction( 413, "ISOS" );
729 createGeomAction( 414, "STEP_VALUE" );
731 createGeomAction( 211, "SHADING" );
732 createGeomAction( 212, "DISPLAY_ALL" );
733 createGeomAction( 214, "ERASE_ALL" );
734 createGeomAction( 216, "DISPLAY" );
735 createGeomAction( 213, "DISPLAY_ONLY" );
736 createGeomAction( 215, "ERASE" );
738 createGeomAction( 901, "POP_RENAME" );
739 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
740 createGeomAction( 80312, "POP_SHADING", "", 0, true );
741 createGeomAction( 8032, "POP_COLOR" );
742 createGeomAction( 8033, "POP_TRANSPARENCY" );
743 createGeomAction( 8034, "POP_ISOS" );
744 createGeomAction( 8001, "POP_CREATE_GROUP" );
746 // make wireframe-shading items to be exclusive (only one at a time is selected)
747 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
748 //dispModeGr->add( action( 80311 ) );
749 //dispModeGr->add( action( 80312 ) );
750 // ---- create menu --------------------------
752 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
753 createMenu( separator(), fileId, 10 );
754 createMenu( 111, fileId, 10 );
755 createMenu( 121, fileId, 10 );
756 createMenu( separator(), fileId, -1 );
758 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
759 createMenu( 33, editId, -1 );
761 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
763 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
764 createMenu( 4011, basicId, -1 );
765 createMenu( 4012, basicId, -1 );
766 createMenu( 4013, basicId, -1 );
767 createMenu( 4014, basicId, -1 );
768 createMenu( 4015, basicId, -1 );
769 createMenu( 4019, basicId, -1 );
770 createMenu( separator(), basicId, -1 );
771 createMenu( 4016, basicId, -1 );
772 createMenu( 4017, basicId, -1 );
773 createMenu( 4018, basicId, -1 );
774 createMenu( 4020, basicId, -1 );
776 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
777 createMenu( 4021, primId, -1 );
778 createMenu( 4022, primId, -1 );
779 createMenu( 4023, primId, -1 );
780 createMenu( 4024, primId, -1 );
781 createMenu( 4025, primId, -1 );
783 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
784 createMenu( 4031, genId, -1 );
785 createMenu( 4032, genId, -1 );
786 createMenu( 4033, genId, -1 );
787 createMenu( 4034, genId, -1 );
788 createMenu( separator(), newEntId, -1 );
790 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
791 createMenu( 800, groupId, -1 );
792 createMenu( 801, groupId, -1 );
793 createMenu( separator(), newEntId, -1 );
795 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
796 createMenu( 9997, blocksId, -1 );
797 createMenu( 9999, blocksId, -1 );
799 createMenu( separator(), newEntId, -1 );
800 createMenu( 404, newEntId, -1 );
801 createMenu( separator(), newEntId, -1 );
802 createMenu( 407, newEntId, -1 );
804 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
805 createMenu( 4081, buildId, -1 );
806 createMenu( 4082, buildId, -1 );
807 createMenu( 4083, buildId, -1 );
808 createMenu( 4084, buildId, -1 );
809 createMenu( 4085, buildId, -1 );
810 createMenu( 4086, buildId, -1 );
812 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
814 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
815 createMenu( 5011, boolId, -1 );
816 createMenu( 5012, boolId, -1 );
817 createMenu( 5013, boolId, -1 );
818 createMenu( 5014, boolId, -1 );
820 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
821 createMenu( 5021, transId, -1 );
822 createMenu( 5022, transId, -1 );
823 createMenu( 5023, transId, -1 );
824 createMenu( 5024, transId, -1 );
825 createMenu( 5025, transId, -1 );
826 createMenu( 5026, transId, -1 );
827 createMenu( separator(), transId, -1 );
828 createMenu( 5027, transId, -1 );
829 createMenu( 5028, transId, -1 );
831 createMenu( 503, operId, -1 );
832 createMenu( 504, operId, -1 );
833 createMenu( separator(), operId, -1 );
834 createMenu( 505, transId, -1 );
835 createMenu( 506, transId, -1 );
836 //createMenu( 507, transId, -1 );
838 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
839 createMenu( 9998, blockId, -1 );
840 createMenu( 9995, blockId, -1 );
841 createMenu( 99991, blockId, -1 );
843 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
844 createMenu( 605, repairId, -1 );
845 createMenu( 603, repairId, -1 );
846 createMenu( 606, repairId, -1 );
847 createMenu( 607, repairId, -1 );
848 createMenu( 604, repairId, -1 );
849 createMenu( 601, repairId, -1 );
850 createMenu( 602, repairId, -1 );
851 createMenu( 608, repairId, -1 );
852 createMenu( 609, repairId, -1 );
853 createMenu( 610, repairId, -1 );
855 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
856 createMenu( 708, measurId, -1 );
857 createMenu( 701, measurId, -1 );
858 createMenu( separator(), measurId, -1 );
859 createMenu( 702, measurId, -1 );
860 createMenu( 703, measurId, -1 );
861 createMenu( separator(), measurId, -1 );
863 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
864 createMenu( 7041, dimId, -1 );
865 createMenu( 7042, dimId, -1 );
866 createMenu( separator(), measurId, -1 );
868 createMenu( 705, measurId, -1 );
869 createMenu( separator(), measurId, -1 );
870 createMenu( 706, measurId, -1 );
871 createMenu( 707, measurId, -1 );
872 createMenu( 7072, measurId, -1 );
874 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 10 );
875 createMenu( separator(), toolsId, -1 );
876 createMenu( 5103, toolsId, -1 );
878 int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 10 );
879 createMenu( separator(), prefId, -1 );
881 int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
882 createMenu( 412, geomId, -1 );
883 createMenu( 413, geomId, -1 );
884 createMenu( 414, geomId, -1 );
885 createMenu( separator(), prefId, -1 );
887 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
888 createMenu( separator(), viewId, -1 );
890 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
891 createMenu( 211, dispmodeId, -1 );
893 createMenu( separator(), viewId, -1 );
894 createMenu( 212, viewId, -1 );
895 createMenu( 214, viewId, -1 );
896 createMenu( separator(), viewId, -1 );
897 createMenu( 216, viewId, -1 );
898 createMenu( 213, viewId, -1 );
899 createMenu( 215, viewId, -1 );
901 // ---- create toolbars --------------------------
903 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
904 createTool( 4011, basicTbId );
905 createTool( 4012, basicTbId );
906 createTool( 4013, basicTbId );
907 createTool( 4014, basicTbId );
908 createTool( 4015, basicTbId );
909 createTool( 4019, basicTbId );
910 createTool( 4016, basicTbId );
911 createTool( 4017, basicTbId );
912 createTool( 4018, basicTbId );
913 createTool( 4020, basicTbId );
915 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
916 createTool( 4021, primTbId );
917 createTool( 4022, primTbId );
918 createTool( 4023, primTbId );
919 createTool( 4024, primTbId );
920 createTool( 4025, primTbId );
922 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
923 createTool( 5011, boolTbId );
924 createTool( 5012, boolTbId );
925 createTool( 5013, boolTbId );
926 createTool( 5014, boolTbId );
928 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
929 createTool( 4031, genTbId );
930 createTool( 4032, genTbId );
931 createTool( 4033, genTbId );
932 createTool( 4034, genTbId );
934 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
935 createTool( 5021, transTbId );
936 createTool( 5022, transTbId );
937 createTool( 5023, transTbId );
938 createTool( 5024, transTbId );
939 createTool( 5025, transTbId );
940 createTool( 5026, transTbId );
941 createTool( separator(), transTbId );
942 createTool( 5027, transTbId );
943 createTool( 5028, transTbId );
945 QtxPopupMgr* mgr = popupMgr();
946 mgr->insert( action( 901 ), -1, -1 ); // rename
947 mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
948 mgr->insert( action( 8001 ), -1, -1 ); // create group
949 mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
950 mgr->insert( action( 801 ), -1, -1 ); // edit group
951 mgr->setRule( action( 801 ), "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
952 mgr->insert( separator(), -1, -1 ); // -----------
953 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
954 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
955 mgr->setRule( action( 80311 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
956 mgr->setRule( action( 80311 ), "$displaymode in {'Wireframe'}", false );
957 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
958 mgr->setRule( action( 80312 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
959 mgr->setRule( action( 80312 ), "$displaymode in {'Shading'}", false );
960 mgr->insert( separator(), -1, -1 ); // -----------
961 mgr->insert( action( 8032 ), -1, -1 ); // color
962 mgr->setRule( action( 8032 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
963 mgr->insert( action( 8033 ), -1, -1 ); // transparency
964 mgr->setRule( action( 8033 ), "$client in {'OCCViewer' 'VTKViewer'} and selcount>0", true );
965 mgr->insert( action( 8034 ), -1, -1 ); // isos
966 mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0", true );
967 mgr->insert( separator(), -1, -1 ); // -----------
968 mgr->insert( action( 216 ), -1, -1 ); // display
969 mgr->setRule( action( 216 ), "isActiveViewer=true and selcount>0 and (($type in {'Shape' 'Group'} and ($isVisible in {false})) or $type in {'Component'})", true );
970 mgr->insert( action( 215 ), -1, -1 ); // erase
971 mgr->setRule( action( 215 ), "isActiveViewer=true and selcount>0 and (($type in {'Shape' 'Group'} and $isVisible in {true}) or ($type in {'Component'} and selcount=1))", true );
972 mgr->insert( action( 214 ), -1, -1 ); // erase All
973 mgr->setRule( action( 214 ), "isActiveViewer=true and $client in {'OCCViewer' 'VTKViewer'}", true );
974 mgr->insert( action( 213 ), -1, -1 ); // display only
975 mgr->setRule( action( 213 ), "isActiveViewer=true and selcount>0 and ($type in {'Shape' 'Group'} or ($type in {'Component'} and selcount=1))", true );
976 mgr->insert( separator(), -1, -1 );
979 //=======================================================================
980 // function : GeometryGUI::Deactivate()
981 // purpose : Called when GEOM module is deactivated [ static ]
982 //=======================================================================
983 bool GeometryGUI::activateModule( SUIT_Study* study )
985 if ( CORBA::is_nil( myComponentGeom ) )
988 bool res = SalomeApp_Module::activateModule( study );
993 setMenuShown( true );
994 setToolShown( true );
996 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
997 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
998 connect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
999 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1001 GUIMap::Iterator it;
1002 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1003 it.data()->activate( application()->desktop() );
1005 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1006 SUIT_ViewManager* vm;
1007 ViewManagerList OCCViewManagers, VTKViewManagers;
1008 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1009 for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1010 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1011 application()->viewManagers( VTKViewer_Viewer::Type(), VTKViewManagers );
1012 for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1013 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1015 // disable OCC selectors
1016 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1017 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1018 sr->setEnabled(true);
1020 // disable VTK selectors
1021 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1022 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1023 sr->setEnabled(true);
1029 //=======================================================================
1030 // function : GeometryGUI::Deactivate()
1031 // purpose : Called when GEOM module is deactivated [ static ]
1032 //=======================================================================
1033 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1035 setMenuShown( false );
1036 setToolShown( false );
1038 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1039 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1040 disconnect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1041 this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
1043 EmitSignalCloseAllDialogs();
1045 GUIMap::Iterator it;
1046 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1047 it.data()->deactivate();
1049 myOCCSelectors.clear();
1050 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1052 myVTKSelectors.clear();
1053 getApp()->selectionMgr()->setEnabled( true, VTKViewer_Viewer::Type() );
1055 return SalomeApp_Module::deactivateModule( study );
1058 //=================================================================================
1059 // function : GeometryGUI::DefinePopup()
1060 // purpose : Called from desktop to define popup menu [static]
1061 //=================================================================================
1063 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1065 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1066 SALOME_Selection* Sel = SALOME_Selection::Selection(ActiveStudy->getSelection());
1071 if ( theParent == "Viewer" ) {
1072 if ( Sel->IObjectCount() == 0 )
1073 theContext = "NothingSelected";
1076 if ( Sel->IObjectCount() == 1 ) {
1077 Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1078 if( IO->hasEntry() ) {
1079 SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1080 if ( !sobj->_is_nil() ) {
1081 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1082 if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1083 // component is selected
1084 theObject = "Component";
1087 GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1088 if ( !CORBA::is_nil( aGObj ) ) {
1089 switch( aGObj->GetType() ) {
1091 theObject = "Group";
1094 theObject = "Shape";
1104 //=================================================================================
1105 // function : GeometryGUI::CustomPopup()
1106 // purpose : Called from desktop to create popup menu [static]
1107 //=================================================================================
1108 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1109 const QString& theParent, const QString& theObject)
1111 GeometryGUI* geomGUI = GetGeomGUI();
1113 // Deactivate any non modal dialog box to get the neutral point
1114 geomGUI->EmitSignalDeactivateDialog();
1115 QAD_Study* anActiveStudy = parent->getActiveStudy();
1116 QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1117 QAD_ViewFrame* aViewFrame = aStudyFrame->getRightFrame()->getViewFrame();
1118 SALOME_Selection* Sel = SALOME_Selection::Selection(anActiveStudy->getSelection());
1119 QString parentComponent = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1120 bool isOCCViewer = aViewFrame->getTypeView() == VIEW_OCC;
1121 bool isVTKViewer = aViewFrame->getTypeView() == VIEW_VTK;
1122 int aDisplayMode = 0;
1125 if ( aViewFrame->getTypeView() == VIEW_OCC )
1126 aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1127 else if ( aViewFrame->getTypeView() == VIEW_VTK )
1128 aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
1130 int nbSel = Sel->IObjectCount();
1133 ////// NOTHING SELECTED
1136 else if ( nbSel == 1 ) {
1137 ////// SINGLE OBJECT SELECTION
1138 if ( parentComponent != parent->getActiveComponent() ) {
1139 ////// selected object does not belong to GEOM module:
1140 // remove all commands except Display/Erase...
1142 int id = popup->idAt( 0 );
1143 if ( id <= QAD_TopLabel_Popup_ID )
1144 popup->removeItemAt( 0 );
1150 ////// selected object belong to the GEOM module
1151 // get interactive object
1152 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1153 objectName = IObject->getName();
1154 // if object has entry get SObject
1155 SALOMEDS::SObject_var SO;
1156 if ( IObject->hasEntry() )
1157 SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1159 if ( theObject == "Component" ) {
1160 ////// menu for component
1161 if ( !isOCCViewer && !isVTKViewer ) {
1162 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1163 popup->removeItem( QAD_Display_Popup_ID );
1164 popup->removeItem( QAD_Erase_Popup_ID );
1168 ////// not component (should be shape)
1169 if ( IObject->hasEntry() ) /////// VSR : TO BE REMOVED
1170 popup->removeItem( 804 ); // "Add in Study"
1172 // Here could be analysis of the geom shape's type
1175 SALOMEDS::GenericAttribute_var aTmpAttr;
1176 if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1177 popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1179 if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1180 if ( theObject == "Shape" )
1181 popup->removeItem( 800 ); // Create Group
1182 else if ( theObject == "Group" )
1183 popup->removeItem( 801 ); // Edit Group
1186 if ( isOCCViewer || isVTKViewer ) {
1187 ////// current viewer is OCC or VTK
1188 SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1189 if ( aViewFrame->isVisible( IObject ) ) {
1190 ////// object is already displayed in the viewer
1191 popup->removeItem( QAD_Display_Popup_ID );
1192 if ( isOCCViewer ) {
1193 ////// OCC viewer only
1194 OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1195 if ( occPrs && !occPrs->IsNull() ) {
1196 AIS_ListOfInteractive ioList;
1197 occPrs->GetObjects( ioList );
1198 QMenuItem* mi = popup->findItem( 803 );
1199 if ( mi && mi->popup() ) {
1200 if ( ioList.First()->DisplayMode() == 0 )
1201 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1202 else if ( ioList.First()->DisplayMode() == 1 )
1203 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1204 else if ( ioList.First()->DisplayMode() < 0 )
1205 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1210 ////// VTK viewer only
1211 popup->removeItem( 8034 ); // "Isos"
1212 VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
1213 if ( vtkPrs && !vtkPrs->IsNull() ) {
1214 vtkActorCollection* actorList = vtkPrs->GetObjects();
1215 actorList->InitTraversal();
1216 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1217 QMenuItem* mi = popup->findItem( 803 );
1218 if ( ac && mi && mi->popup() ) {
1219 if ( ac->getDisplayMode() == 0 )
1220 mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1221 else if ( ac->getDisplayMode() == 1 )
1222 mi->popup()->setItemChecked( 80312, true ); // "Shading"
1224 mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1230 ////// object is not yet displayed in the viewer
1231 popup->removeItem( 803 ); // "Display Mode"
1232 popup->removeItem( 8032 ); // "Color"
1233 popup->removeItem( 8033 ); // "Transparency"
1234 popup->removeItem( 8034 ); // "Isos"
1235 popup->removeItem( QAD_Erase_Popup_ID );
1240 ////// other viewer type (neither OCC nor VTK)
1241 popup->removeItem( 803 ); // "Display Mode"
1242 popup->removeItem( 8032 ); // "Color"
1243 popup->removeItem( 8033 ); // "Transparency"
1244 popup->removeItem( 8034 ); // "Isos"
1245 popup->removeItem( QAD_Display_Popup_ID );
1246 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1247 popup->removeItem( QAD_Erase_Popup_ID );
1253 ////// MULTIPLE SELECTION
1254 if ( parentComponent != parent->getActiveComponent() ) {
1255 ////// not GEOM module objects or objects belong to different modules
1256 // remove all commands except Display/Erase...
1258 int id = popup->idAt( 0 );
1259 if ( id <= QAD_TopLabel_Popup_ID )
1260 popup->removeItemAt( 0 );
1264 if ( parentComponent.isNull() ) {
1265 ////// objects belong to different modules
1266 popup->removeItem(QAD_Display_Popup_ID);
1267 popup->removeItem(QAD_DisplayOnly_Popup_ID);
1268 popup->removeItem(QAD_Erase_Popup_ID);
1271 objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1275 ////// all selected objects belong to GEOM module
1276 popup->removeItem( 901 ); // "Rename"
1278 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1279 bool isComponent = false;
1280 bool needOpen = false;
1281 bool needDisplay = false;
1282 bool needErase = false;
1283 int needToPublish = 0;
1285 for( ;It.More();It.Next() ) {
1286 Handle(SALOME_InteractiveObject) anIObject = It.Value();
1288 if ( aViewFrame->isVisible( anIObject ) )
1293 if( anIObject->hasEntry() ) {
1294 needToPublish = -1; /////// VSR : TO BE REMOVED
1295 SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1296 SALOMEDS::GenericAttribute_var aTmpAttr;
1297 if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1298 needOpen = true; /////// VSR : TO BE REMOVED
1299 if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1303 if ( needToPublish != -1 ) needToPublish = 1;
1306 if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1307 ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1308 popup->removeItem( 803 ); // "Display Mode"
1309 popup->removeItem( 8032 ); // "Color"
1310 popup->removeItem( 8033 ); // "Transparency"
1311 popup->removeItem( 8034 ); // "Isos"
1312 popup->removeItem( 804 ); // "Add in Study"
1313 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1314 popup->removeItem( QAD_Display_Popup_ID );
1315 popup->removeItem( QAD_Erase_Popup_ID );
1318 popup->removeItem( 9024 ); // "Open"
1319 if ( needToPublish <= 0 )
1320 popup->removeItem( 804 ); // "Add in Study"
1323 popup->removeItem( 803 ); // "Display Mode"
1324 popup->removeItem( 8032 ); // "Color"
1325 popup->removeItem( 8033 ); // "Transparency"
1326 popup->removeItem( 8034 ); // "Isos"
1327 popup->removeItem( QAD_DisplayOnly_Popup_ID );
1331 popup->removeItem( QAD_Display_Popup_ID );
1333 popup->removeItem( QAD_Erase_Popup_ID );
1335 popup->removeItem( 8034 ); // "Isos"
1340 // check popup for unnecessary separators
1341 QAD_Tools::checkPopup( popup );
1342 // find popup menu's TopLabel item (with title)
1343 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1344 if ( topItem >= 0 ) {
1345 // remove popup menu's title item
1346 popup->removeItem( QAD_TopLabel_Popup_ID );
1347 if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1348 // set bold font for popup menu's title
1349 QFont f = popup->font(); f.setBold( TRUE );
1350 popup->removeItem( QAD_TopLabel_Popup_ID );
1351 popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1360 //=======================================================================
1361 // function : GeometryGUI::BuildPresentation()
1363 //=======================================================================
1364 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1366 //GEOM_Displayer().Display( io, false, win );
1369 //=======================================================================
1370 // function : setCommandsEnabled()
1371 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1372 //=======================================================================
1373 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1378 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1379 // const bool ViewVTK = ( win->getViewManager()->getType() == VTKViewer_Viewer::Type() );
1381 // disable non-OCC viewframe menu commands
1382 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1383 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1384 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1385 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1386 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1387 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1388 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1389 action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1391 action( 800 )->setEnabled( ViewOCC ); // Create Group
1392 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1394 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1397 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1399 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1400 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1403 void GeometryGUI::viewManagers( QStringList& lst ) const
1405 lst.append( OCCViewer_Viewer::Type() );
1408 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1410 if ( vm->getType() == OCCViewer_Viewer::Type() )
1412 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1413 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1415 // disable OCC selectors
1416 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1417 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1418 sr->setEnabled(true);
1420 else if ( vm->getType() == VTKViewer_Viewer::Type() )
1422 SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1423 myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1425 // disable VTK selectors
1426 getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1427 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1428 sr->setEnabled(true);
1432 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1434 SUIT_ViewModel* viewer = vm->getViewModel();
1435 if ( vm->getType() == OCCViewer_Viewer::Type() )
1437 for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1438 if ( sr->viewer() == viewer )
1440 myOCCSelectors.remove( sr );
1444 if ( vm->getType() == VTKViewer_Viewer::Type() )
1446 for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1447 if ( sr->viewer() == viewer )
1449 myVTKSelectors.remove( sr );
1455 QString GeometryGUI::engineIOR() const
1457 if ( !CORBA::is_nil( GetGeomGen() ) )
1458 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1459 return QString( "" );
1462 SalomeApp_Selection* GeometryGUI::createSelection() const
1464 return new GEOMGUI_Selection();
1467 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1469 SalomeApp_Module::contextMenuPopup( client, menu, title );
1471 getApp()->selectionMgr()->selectedObjects( lst );
1472 if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1473 Handle(SALOME_InteractiveObject) io = lst.First();
1474 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1475 _PTR(Study) study = appStudy->studyDS();
1476 _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1478 title = QString( obj->GetName().c_str() );
1482 void GeometryGUI::createPreferences()
1484 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1486 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1487 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1488 SalomeApp_Preferences::Color, "Geometry", "shading_color" );
1489 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1490 SalomeApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1492 setPreferenceProperty( genGroup, "columns", 1 );
1494 setPreferenceProperty( step, "min", 0.001 );
1495 setPreferenceProperty( step, "max", 10000 );
1496 setPreferenceProperty( step, "precision", 3 );
1499 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )