Salome HOME
Avoid including of SALOMEDS classes; fix pb with objects deletion
[modules/geom.git] / src / GEOMGUI / GeometryGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : GeometryGUI.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GeometryGUI.h"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
32
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ViewManager.h>
37
38 #include <OCCViewer_ViewWindow.h>
39 #include <OCCViewer_ViewPort3d.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
42
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>
48
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>
56
57 // External includes
58 #include <qfileinfo.h>
59 #include <qpainter.h>
60
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <OSD_SharedLibrary.hxx>
64
65 #include <utilities.h>
66
67 #include <vtkCamera.h>
68 #include <vtkRenderer.h>
69
70 extern "C" {
71   Standard_EXPORT CAM_Module* createModule() {
72     return new GeometryGUI();
73   }
74 }
75
76 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil(); 
77
78 bool GeometryGUI::InitGeomGen() 
79 {
80   GeometryGUI aGG;
81   if( CORBA::is_nil( myComponentGeom ) ) return false;   
82   return true; 
83 }                          
84
85 //=======================================================================
86 // function : ClientSObjectToObject
87 // purpose  : 
88 //=======================================================================
89 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
90 {
91   _PTR(GenericAttribute) anAttr;
92   CORBA::Object_var anObj;
93   try {
94     std::string aValue = theSObject->GetIOR();
95     if (strcmp(aValue.c_str(), "") != 0) {
96       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
97       anObj = anORB->string_to_object(aValue.c_str());
98     }
99   } catch(...) {
100     INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
101   }
102   return anObj._retn();
103 }
104
105 //=======================================================================
106 // function : ClientStudyToStudy
107 // purpose  : 
108 //=======================================================================
109 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
110 {
111   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
112   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
113   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
114   int aStudyID = theStudy->StudyId();
115   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
116   return aDSStudy._retn();
117 }
118
119 //=================================================================================
120 // class   : CustomItem
121 // purpose : Set Font to a text.
122 //=================================================================================
123 class CustomItem : public QCustomMenuItem
124 {
125 public:
126   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
127   ~CustomItem() {}
128
129   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
130   {
131     p->save();
132     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
133     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
134     p->setFont( myFont );
135     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
136     p->restore();
137   }
138
139   QSize sizeHint()
140   {
141     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
142   }
143
144   bool fullSpan() const
145   {
146     return true;
147   }
148
149 private:
150   QString myString;
151   QFont   myFont;
152 };
153
154 //=======================================================================
155 // function : GeometryGUI::GeometryGUI()
156 // purpose  : Constructor
157 //=======================================================================
158 GeometryGUI::GeometryGUI() :
159   SalomeApp_Module( "GEOM" )
160 {
161   if ( CORBA::is_nil( myComponentGeom ) )
162   { 
163     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
164     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
165     myComponentGeom  = GEOM::GEOM_Gen::_narrow( comp );
166   }
167   
168   myState           = -1;
169   myActiveDialogBox = 0;
170   myFatherior       = "";
171
172   gp_Pnt origin = gp_Pnt(0., 0., 0.);
173   gp_Dir direction = gp_Dir(0., 0., 1.);
174   myWorkingPlane = gp_Ax3(origin, direction);
175
176   myOCCSelectors.setAutoDelete( true );
177   myVTKSelectors.setAutoDelete( true );
178 }
179
180 //=======================================================================
181 // function : GeometryGUI::~GeometryGUI()
182 // purpose  : Destructor
183 //=======================================================================
184 GeometryGUI::~GeometryGUI()
185 {
186 }
187
188 //=======================================================================
189 // function : GeometryGUI::getLibrary()
190 // purpose  : get or load GUI library by name [ internal ]
191 //=======================================================================
192 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
193 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
194 {
195   if ( !myGUIMap.contains( libraryName ) ) {
196     // try to load library if it is not loaded yet
197     QCString libs;
198     if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
199       QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
200       for( int i = dirList.count()-1; i >= 0; i-- ) {
201         QString dir = dirList[ i ];
202         QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
203         if( fi.exists() ) {
204           OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
205           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
206           if( !res ) {
207             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
208             continue; // continue search further
209           }
210           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
211           if ( osdF != NULL ) {
212             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
213             GEOMGUI* libGUI = (*func)(this);
214             if ( libGUI ) {
215               myGUIMap[ libraryName ] = libGUI;
216               break; // found and loaded!
217             }
218           }
219         }
220       }
221     }
222   }
223   if ( myGUIMap.contains( libraryName ) )
224     // library is successfully loaded
225     return myGUIMap[ libraryName ];
226   return 0;
227 }
228
229 //=======================================================================
230 // function : GeometryGUI::ActiveWorkingPlane()
231 // purpose  : Activate Working Plane View
232 //=======================================================================
233 void GeometryGUI::ActiveWorkingPlane()
234 {
235   gp_Dir DZ = myWorkingPlane.Direction();
236   gp_Dir DY = myWorkingPlane.YDirection();
237
238   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
239   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
240   bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
241
242   if( ViewOCC ) {
243     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
244     if ( vw ) {
245       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
246
247       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
248       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
249
250       vw->onViewFitAll();
251     }
252   }
253   else if( ViewVTK ) {
254     VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
255     if ( vw ) {
256       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
257
258       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
259       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
260       camera->SetFocalPoint(0,0,0);
261
262       vw->onFitAll();
263     }
264   }
265 }
266
267 //=======================================================================
268 // function : GeometryGUI::SetActiveDialogBox()
269 // purpose  : Set active dialog box
270 //=======================================================================
271 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
272 {
273   myActiveDialogBox = (QDialog*)aDlg;
274 }
275
276 //=======================================================================
277 // function : GeometryGUI::EmitSignalDeactivateDialog()
278 // purpose  : Emit a signal to deactivate the active dialog Box
279 //=======================================================================
280 void GeometryGUI::EmitSignalDeactivateDialog()
281 {
282   emit SignalDeactivateActiveDialog();
283 }
284
285 //=======================================================================
286 // function : GeometryGUI::EmitSignalCloseAllDialogs()
287 // purpose  : Emit a signal to close all non modal dialogs box
288 //=======================================================================
289 void GeometryGUI::EmitSignalCloseAllDialogs()
290 {
291   emit SignalCloseAllDialogs();
292 }
293
294 //=======================================================================
295 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
296 // purpose  : Emit a signal to inform that default real spin box step has
297 //            been changed
298 //=======================================================================
299 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
300 {
301   emit SignalDefaultStepValueChanged(newVal);
302 }
303
304 //=======================================================================
305 // function : GeometryGUI::OnGUIEvent()
306 // purpose  : common slot for all menu/toolbar actions
307 //=======================================================================
308 void GeometryGUI::OnGUIEvent()
309 {
310   const QObject* obj = sender();
311   if ( !obj || !obj->inherits( "QAction" ) )
312     return;
313   int id = actionId((QAction*)obj);
314   if ( id != -1 )
315     OnGUIEvent( id );
316 }
317
318 //=======================================================================
319 // function : GeometryGUI::OnGUIEvent()
320 // purpose  : manage all events on GUI [static]
321 //=======================================================================
322 void GeometryGUI::OnGUIEvent( int id )
323 {
324   SUIT_Desktop* desk = application()->desktop();
325
326   // check type of the active viewframe
327   SUIT_ViewWindow* window = desk->activeWindow();
328   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
329   bool ViewVTK = ( window && window->getViewManager()->getType() == VTKViewer_Viewer::Type() );
330   // if current viewframe is not of OCC and not of VTK type - return immediately
331   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
332   bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 ); 
333   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
334       return;
335
336   // fix for IPAL9103, point 2
337   if ( CORBA::is_nil( GetGeomGen() ) ) {
338     SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
339     return;
340   }
341
342   GEOMGUI* library = 0;
343   // try to get-or-load corresponding GUI library
344   if( id == 111  ||  // MENU FILE - IMPORT BREP
345       id == 112  ||  // MENU FILE - IMPORT IGES
346       id == 113  ||  // MENU FILE - IMPORT STEP
347       id == 121  ||  // MENU FILE - EXPORT BREP
348       id == 122  ||  // MENU FILE - EXPORT IGES
349       id == 123  ||  // MENU FILE - EXPORT STEP
350       id == 31   ||  // MENU EDIT - COPY
351       id == 33   ||  // MENU EDIT - DELETE
352       id == 411  ||  // MENU SETTINGS - ADD IN STUDY
353       id == 412  ||  // MENU SETTINGS - SHADING COLOR
354       id == 413  ||  // MENU SETTINGS - ISOS
355       id == 414  ||  // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
356       id == 5103 ||  // MENU TOOLS - CHECK GEOMETRY
357       id == 8032 ||  // POPUP VIEWER - COLOR
358       id == 8033 ||  // POPUP VIEWER - TRANSPARENCY
359       id == 8034 ||  // POPUP VIEWER - ISOS
360       id == 804  ||  // POPUP VIEWER - ADD IN STUDY
361       id == 901  ||  // OBJECT BROWSER - RENAME
362       id == 9024 ) { // OBJECT BROWSER - OPEN
363     //cout << "id " << id << " received" << endl;
364     library = getLibrary( "libGEOMToolsGUI.so" );
365   }
366   else if( id == 211  ||  // MENU VIEW - WIREFRAME/SHADING
367            id == 212  ||  // MENU VIEW - DISPLAY ALL
368            id == 213  ||  // MENU VIEW - DISPLAY ONLY
369            id == 214  ||  // MENU VIEW - ERASE ALL
370            id == 215  ||  // MENU VIEW - ERASE
371            id == 216  ||  // MENU VIEW - DISPLAY
372            id == 80311 ||  // POPUP VIEWER - WIREFRAME
373            id == 80312 ) { // POPUP VIEWER - SHADING
374     library = getLibrary( "libDisplayGUI.so" );
375   }
376   else if( id == 4011 ||  // MENU BASIC - POINT
377            id == 4012 ||  // MENU BASIC - LINE
378            id == 4013 ||  // MENU BASIC - CIRCLE
379            id == 4014 ||  // MENU BASIC - ELLIPSE
380            id == 4015 ||  // MENU BASIC - ARC
381            id == 4016 ||  // MENU BASIC - VECTOR
382            id == 4017 ||  // MENU BASIC - PLANE
383            id == 4018 ||  // MENU BASIC - WPLANE
384            id == 4019 ||  // MENU BASIC - CURVE
385            id == 4020 ) { // MENU BASIC - REPAIR
386     library = getLibrary( "libBasicGUI.so" );
387   }
388   else if( id == 4021 ||  // MENU PRIMITIVE - BOX
389            id == 4022 ||  // MENU PRIMITIVE - CYLINDER
390            id == 4023 ||  // MENU PRIMITIVE - SPHERE
391            id == 4024 ||  // MENU PRIMITIVE - TORUS
392            id == 4025 ) { // MENU PRIMITIVE - CONE
393     library = getLibrary( "libPrimitiveGUI.so" );
394   }
395   else if( id == 4031 ||  // MENU GENERATION - PRISM
396            id == 4032 ||  // MENU GENERATION - REVOLUTION
397            id == 4033 ||  // MENU GENERATION - FILLING
398            id == 4034 ) { // MENU GENERATION - PIPE
399     library = getLibrary( "libGenerationGUI.so" );
400   }
401   else if( id == 404 ||   // MENU ENTITY - SKETCHER
402            id == 407 ) {  // MENU ENTITY - EXPLODE
403     library = getLibrary( "libEntityGUI.so" );
404   }
405   else if( id == 4081 ||  // MENU BUILD - EDGE
406            id == 4082 ||  // MENU BUILD - WIRE
407            id == 4083 ||  // MENU BUILD - FACE
408            id == 4084 ||  // MENU BUILD - SHELL
409            id == 4085 ||  // MENU BUILD - SOLID
410            id == 4086 ) { // MENU BUILD - COMPUND
411     library = getLibrary( "libBuildGUI.so" );
412   }
413   else if( id == 5011 ||  // MENU BOOLEAN - FUSE
414            id == 5012 ||  // MENU BOOLEAN - COMMON
415            id == 5013 ||  // MENU BOOLEAN - CUT
416            id == 5014 ) { // MENU BOOLEAN - SECTION
417     library = getLibrary( "libBooleanGUI.so" );
418   }
419   else if( id == 5021 ||  // MENU TRANSFORMATION - TRANSLATION
420            id == 5022 ||  // MENU TRANSFORMATION - ROTATION
421            id == 5023 ||  // MENU TRANSFORMATION - LOCATION
422            id == 5024 ||  // MENU TRANSFORMATION - MIRROR
423            id == 5025 ||  // MENU TRANSFORMATION - SCALE
424            id == 5026 ||  // MENU TRANSFORMATION - OFFSET
425            id == 5027 ||  // MENU TRANSFORMATION - MULTI-TRANSLATION
426            id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
427     library = getLibrary( "libTransformationGUI.so" );
428   }
429   else if( id == 503 ||   // MENU OPERATION - PARTITION
430            id == 504 ||   // MENU OPERATION - ARCHIMEDE
431            id == 505 ||   // MENU OPERATION - FILLET
432            id == 506 ||   // MENU OPERATION - CHAMFER  
433            id == 507 ) {  // MENU OPERATION - CLIPPING RANGE
434     library = getLibrary( "libOperationGUI.so" );
435   }
436   else if( id == 601 ||   // MENU REPAIR - SEWING
437            id == 603 ||   // MENU REPAIR - SUPPRESS FACES
438            id == 604 ||   // MENU REPAIR - SUPPRESS HOLE
439            id == 605 ||   // MENU REPAIR - SHAPE PROCESSING
440            id == 606 ||   // MENU REPAIR - CLOSE CONTOUR
441            id == 607 ||   // MENU REPAIR - REMOVE INTERNAL WIRES
442            id == 608 ||   // MENU REPAIR - ADD POINT ON EDGE
443            id == 609 ||   // MENU REPAIR - FREE BOUNDARIES
444            id == 610 ||   // MENU REPAIR - FREE FACES
445            id == 602 ) {  // MENU REPAIR - GLUE FACES
446     library = getLibrary( "libRepairGUI.so" );
447   }
448   else if( id == 701   ||  // MENU MEASURE - PROPERTIES
449            id == 702   ||  // MENU MEASURE - CDG
450            id == 703   ||  // MENU MEASURE - INERTIA
451            id == 7041  ||  // MENU MEASURE - BOUNDING BOX
452            id == 7042  ||  // MENU MEASURE - MIN DISTANCE
453            id == 705   ||  // MENU MEASURE - TOLERANCE
454            id == 706   ||  // MENU MEASURE - WHATIS
455            id == 707   ||  // MENU MEASURE - CHECK
456            id == 7072  ||  // MENU MEASURE - CHECK COMPOUND OF BLOCKS
457            id == 708 ) {  // MENU MEASURE - POINT COORDINATES
458     library = getLibrary( "libMeasureGUI.so" );
459   }
460   else if( id == 800  ||  // MENU GROUP - CREATE
461            id == 8001 ||  // POPUP MENU - CREATE GROUP
462            id == 801 ) {  // MENU GROUP - EDIT
463     library = getLibrary( "libGroupGUI.so" );
464   }
465   else if( id == 9999  ||  // MENU BLOCKS - HEXAHEDRAL SOLID
466            id == 9998  ||  // MENU BLOCKS - MULTI-TRANSFORMATION
467            id == 9997  ||  // MENU BLOCKS - QUADRANGLE FACE
468            id == 99991 ||  // MENU BLOCKS - PROPAGATE
469            id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
470     library = getLibrary( "libBlocksGUI.so" );
471   }
472
473   // call method of corresponding GUI library
474   if ( library ) 
475     library->OnGUIEvent( id, desk );
476   else 
477     SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
478 }
479
480
481 //=================================================================================
482 // function : GeometryGUI::OnKeyPress()
483 // purpose  : Called when any key is pressed by user [static]
484 //=================================================================================
485 bool GeometryGUI::OnKeyPress( QKeyEvent* pe, SUIT_ViewWindow* win )
486 {
487   GUIMap::Iterator it;
488   bool bOk = true;
489   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
490     bOk = bOk && it.data()->OnKeyPress( pe, application()->desktop(), win );
491   return bOk;
492 }
493
494
495 //=================================================================================
496 // function : GeometryGUI::OnMouseMove()
497 // purpose  : Manages mouse move events [static]
498 //=================================================================================
499 bool GeometryGUI::OnMouseMove( QMouseEvent* pe, SUIT_ViewWindow* win )
500 {  
501   GUIMap::Iterator it;
502   bool bOk = true;
503   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
504     bOk = bOk && it.data()->OnMouseMove( pe, application()->desktop(), win );
505   return bOk;
506 }
507
508
509 //=================================================================================
510 // function : GeometryGUI::0nMousePress()
511 // purpose  : Manage mouse press events [static]
512 //=================================================================================
513 bool GeometryGUI::OnMousePress( QMouseEvent* pe, SUIT_ViewWindow* win )
514 {
515   GUIMap::Iterator it;
516   // OnMousePress() should return false if this event should be processed further
517   // (see OCCViewer_Viewer3d::onMousePress() for explanation)
518   bool processed = false;
519   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
520     processed = processed || it.data()->OnMousePress( pe, application()->desktop(), win );
521   return processed;
522 }
523
524 /*
525 static void UpdateVtkSelection()
526 {
527   QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
528   SUIT_ViewWindow* win = 0;
529   for ( win = winList.first(); win; win = winList.next() ) {
530     if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
531       VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
532       if ( vw ) {
533         VTKViewer_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
534         anInteractor->SetSelectionProp();
535         anInteractor->SetSelectionTolerance();
536         SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
537         if (aStyle) {
538           aStyle->setPreselectionProp();
539         }
540       }
541     }
542   }
543 }
544
545 //=================================================================================
546 // function : GeometryGUI::SetSettings()
547 // purpose  : Called when GEOM module is activated [static]
548 //=================================================================================
549 bool GeometryGUI::SetSettings()
550 {
551   QMenuBar*     Mb = parent->getMainMenuBar();
552   SUIT_Study*   ActiveStudy = application()->activeStudy();
553     
554 // Wireframe or Shading
555   int DisplayMode = 0;
556   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
557   bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
558   bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
559   if ( ViewOCC ) {
560     OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
561     if ( vm ) {
562       Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
563       DisplayMode = ic->DisplayMode();
564     }
565   }
566   else if ( ViewVTK ) {
567     VTKViewer_ViewWindow* vw = dynamic_cast<VTKViewer_ViewWindow*>( window );
568     if ( vw ) {
569       VTKViewer_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
570       DisplayMode = myRenderInter->GetDisplayMode();
571     }
572   }
573
574   if( DisplayMode == 1 )
575     getApp()->
576     Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
577   else
578     Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
579
580
581   // Add in Study  - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
582   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
583   int Settings_AddInStudy;
584   //  if(!AddInStudy.isEmpty())
585   //    Settings_AddInStudy = AddInStudy.toInt();
586   //  else
587   
588   Settings_AddInStudy = 1;
589   Mb->setItemChecked(411, Settings_AddInStudy);
590
591   // step value 
592   QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
593   if(S.isEmpty())
594     QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
595
596   // isos 
597   int count = ActiveStudy->getStudyFramesCount();
598   for(int i = 0; i < count; i++) {
599     if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
600       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
601       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
602
603       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
604       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
605       if(!IsoU.isEmpty())
606         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
607       if(!IsoV.isEmpty())
608         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
609     }
610   }
611
612   setActionsEnabled();
613
614   // PAL5356: update VTK selection
615   ::UpdateVtkSelection();
616   bool bOk = true;
617   GUIMap::Iterator it;
618   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
619     bOk = bOk && it.data()->SetSettings( parent );
620     
621   // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)        
622   if (getenv( "GEOM_CLIPPING" ) == NULL)
623     {
624       QMenuItem* mi = Mb->findItem(50);
625       if (mi && mi->popup())
626       mi->popup()->removeItem(507);     
627     } 
628     
629   return bOk;
630 }
631 */
632
633 //=======================================================================
634 // function : createGeomAction
635 // purpose  : 
636 //=======================================================================
637 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
638 {
639   QIconSet icon;
640   QWidget* parent = application()->desktop();
641   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
642   QPixmap pix;
643   if ( icon_id.length() ) 
644     pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
645   else
646     pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
647   if ( !pix.isNull() )
648     icon = QIconSet( pix );
649
650   QString tooltip    = tr( QString( "TOP_" )+po_id ),
651           menu       = tr( QString( "MEN_" )+po_id ),
652           status_bar = tr( QString( "STB_" )+po_id );
653
654   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
655 }
656
657
658
659 //=======================================================================
660 // function : GeometryGUI::Deactivate()
661 // purpose  : Called when GEOM module is deactivated [ static ]
662 //=======================================================================
663 void GeometryGUI::initialize( CAM_Application* app )
664 {
665   SalomeApp_Module::initialize( app );
666
667   // ----- create actions --------------
668
669   createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
670   createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
671
672   createGeomAction( 33, "DELETE" );
673
674   createGeomAction( 4011, "POINT" );
675   createGeomAction( 4012, "LINE" );
676   createGeomAction( 4013, "CIRCLE" );
677   createGeomAction( 4014, "ELLIPSE" );
678   createGeomAction( 4015, "ARC" );
679   createGeomAction( 4019, "CURVE" );
680   createGeomAction( 4016, "VECTOR" );
681   createGeomAction( 4017, "PLANE" );
682   createGeomAction( 4018, "WORK_PLANE" );
683   createGeomAction( 4020, "LOCAL_CS" );
684
685   createGeomAction( 4021, "BOX" );
686   createGeomAction( 4022, "CYLINDER" );
687   createGeomAction( 4023, "SPHERE" );
688   createGeomAction( 4024, "TORUS" );
689   createGeomAction( 4025, "CONE" );
690
691   createGeomAction( 4031, "EXTRUSION" );
692   createGeomAction( 4032, "REVOLUTION" );
693   createGeomAction( 4033, "FILLING" );
694   createGeomAction( 4034, "PIPE" );
695
696   createGeomAction( 800, "GROUP_CREATE" );
697   createGeomAction( 801, "GROUP_EDIT" );
698
699   createGeomAction( 9997, "Q_FACE" );
700   createGeomAction( 9999, "HEX_SOLID" );
701
702   createGeomAction( 404, "SKETCH" );
703   createGeomAction( 407, "EXPLODE" );
704
705   createGeomAction( 4081, "EDGE" );
706   createGeomAction( 4082, "WIRE" );
707   createGeomAction( 4083, "FACE" );
708   createGeomAction( 4084, "SHELL" );
709   createGeomAction( 4085, "SOLID" );
710   createGeomAction( 4086, "COMPOUND" );
711
712   createGeomAction( 5011, "FUSE" );
713   createGeomAction( 5012, "COMMON" );
714   createGeomAction( 5013, "CUT" );
715   createGeomAction( 5014, "SECTION" );
716
717   createGeomAction( 5021, "TRANSLATION" );
718   createGeomAction( 5022, "ROTATION" );
719   createGeomAction( 5023, "MODIFY_LOCATION" );
720   createGeomAction( 5024, "MIRROR" );
721   createGeomAction( 5025, "SCALE" );
722   createGeomAction( 5026, "OFFSET" );
723   createGeomAction( 5027, "MUL_TRANSLATION" );
724   createGeomAction( 5028, "MUL_ROTATION" );
725
726   createGeomAction( 503, "PARTITION" );
727   createGeomAction( 504, "ARCHIMEDE" );
728   createGeomAction( 505, "FILLET" );
729   createGeomAction( 506, "CHAMFER" );
730   //createGeomAction( 507, "CLIPPING" );
731
732   createGeomAction( 9998, "MUL_TRANSFORM" );
733   createGeomAction( 9995, "EXPLODE_BLOCKS" );
734   createGeomAction( 99991, "PROPAGATE" );
735
736   createGeomAction( 601, "SEWING" );
737   createGeomAction( 602, "GLUE_FACES" );
738   createGeomAction( 603, "SUPPRESS_FACES" );
739   createGeomAction( 604, "SUPPERSS_HOLES" );
740   createGeomAction( 605, "SHAPE_PROCESS" );
741   createGeomAction( 606, "CLOSE_CONTOUR" );
742   createGeomAction( 607, "SUPPRESS_INT_WIRES" );
743   createGeomAction( 608, "POINT_ON_EDGE" );
744   createGeomAction( 609, "CHECK_FREE_BNDS" );
745   createGeomAction( 610, "CHECK_FREE_FACES" );
746   
747   createGeomAction( 708, "POINT_COORDS" );
748   createGeomAction( 701, "BASIC_PROPS" );
749   createGeomAction( 702, "MASS_CENTER" );
750   createGeomAction( 703, "INERTIA" );
751   createGeomAction( 7041, "BND_BOX" );
752   createGeomAction( 7042, "MIN_DIST" );
753
754   createGeomAction( 705, "TOLERANCE" );
755   createGeomAction( 706, "WHAT_IS" );
756   createGeomAction( 707, "CHECK" );
757   createGeomAction( 7072, "CHECK_COMPOUND" );
758
759   createGeomAction( 5103, "CHECK_GEOMETRY" );
760   
761   createGeomAction( 412, "SHADING_COLOR" );
762   createGeomAction( 413, "ISOS" );
763   createGeomAction( 414, "STEP_VALUE" );
764
765   createGeomAction( 211, "SHADING" );
766   createGeomAction( 212, "DISPLAY_ALL" );
767   createGeomAction( 214, "ERASE_ALL" );
768   createGeomAction( 216, "DISPLAY" );
769   createGeomAction( 213, "DISPLAY_ONLY" );
770   createGeomAction( 215, "ERASE" );
771
772   createGeomAction( 901, "POP_RENAME" );
773   createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
774   createGeomAction( 80312, "POP_SHADING", "", 0, true );
775   createGeomAction( 8032, "POP_COLOR" );
776   createGeomAction( 8033, "POP_TRANSPARENCY" );
777   createGeomAction( 8034, "POP_ISOS" );
778   createGeomAction( 8001, "POP_CREATE_GROUP" );
779
780   // make wireframe-shading items to be exclusive (only one at a time is selected)
781   //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
782   //dispModeGr->add( action( 80311 ) );
783   //dispModeGr->add( action( 80312 ) );
784   // ---- create menu --------------------------
785
786   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
787   createMenu( separator(), fileId, 10 );
788   createMenu( 111, fileId, 10 );
789   createMenu( 121, fileId, 10 );
790   createMenu( separator(), fileId, -1 );
791
792   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
793   createMenu( 33, editId, -1 );
794
795   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
796
797   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
798   createMenu( 4011, basicId, -1 );
799   createMenu( 4012, basicId, -1 );
800   createMenu( 4013, basicId, -1 );
801   createMenu( 4014, basicId, -1 );
802   createMenu( 4015, basicId, -1 );
803   createMenu( 4019, basicId, -1 );
804   createMenu( separator(), basicId, -1 );
805   createMenu( 4016, basicId, -1 );
806   createMenu( 4017, basicId, -1 );
807   createMenu( 4018, basicId, -1 );
808   createMenu( 4020, basicId, -1 );
809
810   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
811   createMenu( 4021, primId, -1 );  
812   createMenu( 4022, primId, -1 );  
813   createMenu( 4023, primId, -1 );  
814   createMenu( 4024, primId, -1 );  
815   createMenu( 4025, primId, -1 );  
816
817   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
818   createMenu( 4031, genId, -1 );  
819   createMenu( 4032, genId, -1 );  
820   createMenu( 4033, genId, -1 );  
821   createMenu( 4034, genId, -1 );  
822   createMenu( separator(), newEntId, -1 );
823
824   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
825   createMenu( 800, groupId, -1 );  
826   createMenu( 801, groupId, -1 );  
827   createMenu( separator(), newEntId, -1 );
828
829   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
830   createMenu( 9997, blocksId, -1 );  
831   createMenu( 9999, blocksId, -1 );  
832
833   createMenu( separator(), newEntId, -1 );
834   createMenu( 404, newEntId, -1 );  
835   createMenu( separator(), newEntId, -1 );
836   createMenu( 407, newEntId, -1 );  
837
838   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
839   createMenu( 4081, buildId, -1 );  
840   createMenu( 4082, buildId, -1 );  
841   createMenu( 4083, buildId, -1 );  
842   createMenu( 4084, buildId, -1 );  
843   createMenu( 4085, buildId, -1 );  
844   createMenu( 4086, buildId, -1 );  
845
846   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
847
848   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
849   createMenu( 5011, boolId, -1 );  
850   createMenu( 5012, boolId, -1 );  
851   createMenu( 5013, boolId, -1 );  
852   createMenu( 5014, boolId, -1 );  
853
854   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
855   createMenu( 5021, transId, -1 );  
856   createMenu( 5022, transId, -1 );  
857   createMenu( 5023, transId, -1 );  
858   createMenu( 5024, transId, -1 );  
859   createMenu( 5025, transId, -1 );  
860   createMenu( 5026, transId, -1 );  
861   createMenu( separator(), transId, -1 );
862   createMenu( 5027, transId, -1 );  
863   createMenu( 5028, transId, -1 );  
864
865   createMenu( 503, operId, -1 );  
866   createMenu( 504, operId, -1 );  
867   createMenu( separator(), operId, -1 );
868   createMenu( 505, transId, -1 );  
869   createMenu( 506, transId, -1 );  
870   //createMenu( 507, transId, -1 );  
871
872   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
873   createMenu( 9998, blockId, -1 );  
874   createMenu( 9995, blockId, -1 );  
875   createMenu( 99991, blockId, -1 );  
876
877   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
878   createMenu( 605, repairId, -1 );  
879   createMenu( 603, repairId, -1 );  
880   createMenu( 606, repairId, -1 );  
881   createMenu( 607, repairId, -1 );  
882   createMenu( 604, repairId, -1 );  
883   createMenu( 601, repairId, -1 );  
884   createMenu( 602, repairId, -1 );  
885   createMenu( 608, repairId, -1 );  
886   createMenu( 609, repairId, -1 );  
887   createMenu( 610, repairId, -1 );  
888
889   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
890   createMenu( 708, measurId, -1 );  
891   createMenu( 701, measurId, -1 );  
892   createMenu( separator(), measurId, -1 );
893   createMenu( 702, measurId, -1 );  
894   createMenu( 703, measurId, -1 );  
895   createMenu( separator(), measurId, -1 );
896
897   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
898   createMenu( 7041, dimId, -1 );  
899   createMenu( 7042, dimId, -1 );
900   createMenu( separator(), measurId, -1 );
901   
902   createMenu( 705, measurId, -1 );  
903   createMenu( separator(), measurId, -1 );
904   createMenu( 706, measurId, -1 );  
905   createMenu( 707, measurId, -1 );  
906   createMenu( 7072, measurId, -1 );  
907
908   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
909   createMenu( separator(), toolsId, -1 );
910   createMenu( 5103, toolsId, -1 );  
911   
912   //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
913   //createMenu( separator(), prefId, -1 );
914   //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
915   //createMenu( 412, geomId, -1 );  
916   //createMenu( 413, geomId, -1 );  
917   //createMenu( 414, geomId, -1 );  
918   //createMenu( separator(), prefId, -1 );
919
920   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
921   createMenu( separator(), viewId, -1 );
922
923   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
924   createMenu( 211, dispmodeId, -1 );  
925   
926   createMenu( separator(), viewId, -1 );
927   createMenu( 212, viewId, -1 );  
928   createMenu( 214, viewId, -1 );  
929   createMenu( separator(), viewId, -1 );
930   createMenu( 216, viewId, -1 );  
931   createMenu( 213, viewId, -1 );  
932   createMenu( 215, viewId, -1 );
933
934   // ---- create toolbars --------------------------
935
936   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
937   createTool( 4011, basicTbId );
938   createTool( 4012, basicTbId );
939   createTool( 4013, basicTbId );
940   createTool( 4014, basicTbId );
941   createTool( 4015, basicTbId );
942   createTool( 4019, basicTbId );
943   createTool( 4016, basicTbId );
944   createTool( 4017, basicTbId );
945   createTool( 4018, basicTbId );
946   createTool( 4020, basicTbId );
947
948   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
949   createTool( 4021, primTbId );  
950   createTool( 4022, primTbId );  
951   createTool( 4023, primTbId );  
952   createTool( 4024, primTbId );  
953   createTool( 4025, primTbId );  
954
955   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
956   createTool( 5011, boolTbId );  
957   createTool( 5012, boolTbId );  
958   createTool( 5013, boolTbId );  
959   createTool( 5014, boolTbId );  
960
961   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
962   createTool( 4031, genTbId );  
963   createTool( 4032, genTbId );  
964   createTool( 4033, genTbId );  
965   createTool( 4034, genTbId );  
966
967   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
968   createTool( 5021, transTbId );  
969   createTool( 5022, transTbId );  
970   createTool( 5023, transTbId );  
971   createTool( 5024, transTbId );  
972   createTool( 5025, transTbId );  
973   createTool( 5026, transTbId );  
974   createTool( separator(), transTbId );
975   createTool( 5027, transTbId );  
976   createTool( 5028, transTbId );
977
978   QtxPopupMgr* mgr = popupMgr();
979   mgr->insert( action(  901 ), -1, -1 ); // rename
980   mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
981   mgr->insert( action(  8001 ), -1, -1 ); // create group
982   mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
983   mgr->insert( action(  801 ), -1, -1 ); // edit group
984   mgr->setRule( action( 801 ),  "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
985   mgr->insert( separator(), -1, -1 );        // -----------
986   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
987   mgr->insert( action(  80311 ), dispmodeId, -1 ); // wireframe
988   mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
989   mgr->setRule( action( 80311 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Wireframe'", false );
990   mgr->insert( action(  80312 ), dispmodeId, -1 ); // shading
991   mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
992   mgr->setRule( action( 80312 ), "(client='OCCViewer' or client='VTKViewer') and displaymode='Shading'", false );
993   mgr->insert( separator(), -1, -1 );        // -----------
994   mgr->insert( action(  8032 ), -1, -1 ); // color
995   mgr->setRule( action( 8032 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
996   mgr->insert( action(  8033 ), -1, -1 ); // transparency
997   mgr->setRule( action( 8033 ), "(client='OCCViewer' or client='VTKViewer') and selcount>0", true );
998   mgr->insert( action(  8034 ), -1, -1 ); // isos
999   mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0", true );
1000   mgr->insert( separator(), -1, -1 );        // -----------
1001   mgr->insert( action(  216 ), -1, -1 ); // display
1002   mgr->setRule( action( 216 ), "(selcount>0) and (((isActiveView=true) and (($type in {'Shape' 'Group'} and isVisible=false) or type='Component'))"
1003                                "or ((isActiveView=false) and ($type in {'Shape' 'Group' 'Component'})))", true );
1004   mgr->insert( action(  215 ), -1, -1 ); // erase
1005   mgr->setRule( action( 215 ), "(isActiveView=true) and (($type in {'Shape' 'Group'} and isVisible=true and selcount>0) or (type='Component' and selcount=1))", true );
1006   mgr->insert( action(  214 ), -1, -1 ); // erase All
1007   mgr->setRule( action( 214 ), "client='OCCViewer' or client='VTKViewer'", true );
1008   mgr->insert( action(  213 ), -1, -1 ); // display only
1009   mgr->setRule( action( 213 ), "($type in {'Shape' 'Group'} and selcount>0) or (type='Component' and selcount=1)", true );
1010   mgr->insert( separator(), -1, -1 );
1011 }
1012
1013 //=======================================================================
1014 // function : GeometryGUI::Deactivate()
1015 // purpose  : Called when GEOM module is deactivated [ static ]
1016 //=======================================================================
1017 bool GeometryGUI::activateModule( SUIT_Study* study )
1018 {
1019   if ( CORBA::is_nil( myComponentGeom ) )
1020     return false;
1021
1022   bool res = SalomeApp_Module::activateModule( study );
1023
1024   if ( !res )
1025     return false;
1026
1027   setMenuShown( true );
1028   setToolShown( true );
1029
1030   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), 
1031           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1032   connect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1033            this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); 
1034
1035   GUIMap::Iterator it;
1036   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1037     it.data()->activate( application()->desktop() );
1038
1039   SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1040   SUIT_ViewManager* vm;
1041   ViewManagerList OCCViewManagers, VTKViewManagers;
1042   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1043   for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1044     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1045   application()->viewManagers( VTKViewer_Viewer::Type(), VTKViewManagers );
1046   for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1047     myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1048
1049   // disable OCC selectors
1050   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1051   for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1052     sr->setEnabled(true);
1053   
1054   // disable VTK selectors
1055   getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1056   for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1057     sr->setEnabled(true);
1058   
1059   return true;
1060 }
1061
1062
1063 //=======================================================================
1064 // function : GeometryGUI::Deactivate()
1065 // purpose  : Called when GEOM module is deactivated [ static ]
1066 //=======================================================================
1067 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1068 {
1069   setMenuShown( false );
1070   setToolShown( false );
1071
1072   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), 
1073              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1074   disconnect( (STD_Application*)application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
1075              this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) ); 
1076
1077   EmitSignalCloseAllDialogs();
1078
1079   GUIMap::Iterator it;
1080   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1081     it.data()->deactivate();  
1082
1083   myOCCSelectors.clear();
1084   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1085
1086   myVTKSelectors.clear();
1087   getApp()->selectionMgr()->setEnabled( true, VTKViewer_Viewer::Type() );
1088
1089   return SalomeApp_Module::deactivateModule( study );
1090 }
1091
1092 //=================================================================================
1093 // function : GeometryGUI::DefinePopup()
1094 // purpose  : Called from desktop to define popup menu [static]
1095 //=================================================================================
1096 /*
1097 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1098 {
1099   QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1100   SALOME_Selection* Sel  = SALOME_Selection::Selection(ActiveStudy->getSelection());
1101
1102   theObject  = "";
1103   theContext = "";
1104
1105   if ( theParent == "Viewer" ) {
1106     if ( Sel->IObjectCount() == 0 )
1107       theContext = "NothingSelected";
1108   }
1109
1110   if ( Sel->IObjectCount() == 1 ) {
1111     Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1112     if( IO->hasEntry() ) {
1113       SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1114       if ( !sobj->_is_nil() ) {
1115         SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1116         if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1117           // component is selected
1118           theObject = "Component";
1119         }
1120         else {
1121           GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1122           if ( !CORBA::is_nil( aGObj ) ) {
1123             switch( aGObj->GetType() ) {
1124             case GEOM_GROUP:
1125               theObject = "Group";
1126               break;
1127             default:
1128               theObject = "Shape";
1129               break;
1130             }
1131           }
1132         }
1133       }
1134     }
1135   }
1136 }
1137
1138 //=================================================================================
1139 // function : GeometryGUI::CustomPopup()
1140 // purpose  : Called from desktop to create popup menu [static]
1141 //=================================================================================
1142 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1143                               const QString& theParent, const QString& theObject)
1144 {
1145   GeometryGUI* geomGUI = GetGeomGUI();
1146
1147   // Deactivate any non modal dialog box to get the neutral point
1148   geomGUI->EmitSignalDeactivateDialog();
1149   QAD_Study* anActiveStudy    = parent->getActiveStudy();
1150   QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1151   QAD_ViewFrame* aViewFrame   = aStudyFrame->getRightFrame()->getViewFrame();
1152   SALOME_Selection* Sel       = SALOME_Selection::Selection(anActiveStudy->getSelection());
1153   QString parentComponent     = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1154   bool isOCCViewer            = aViewFrame->getTypeView() == VIEW_OCC;
1155   bool isVTKViewer            = aViewFrame->getTypeView() == VIEW_VTK;
1156   int aDisplayMode            = 0;
1157   QString objectName;
1158
1159   if ( aViewFrame->getTypeView() == VIEW_OCC )
1160     aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1161   else if ( aViewFrame->getTypeView() == VIEW_VTK )
1162     aDisplayMode = ((VTKViewer_ViewFrame*)aViewFrame)->getRWInteractor()->GetDisplayMode();
1163
1164   int nbSel = Sel->IObjectCount();
1165
1166   if( nbSel == 0 ) {
1167     ////// NOTHING SELECTED
1168     popup->clear();
1169   } 
1170   else if ( nbSel == 1 ) {
1171     ////// SINGLE OBJECT SELECTION
1172     if ( parentComponent != parent->getActiveComponent() )  {
1173       ////// selected object does not belong to GEOM module:
1174       // remove all commands except Display/Erase...
1175       while ( 1 ) {
1176         int id = popup->idAt( 0 );
1177         if ( id <= QAD_TopLabel_Popup_ID )
1178           popup->removeItemAt( 0 );
1179         else
1180           break;
1181       }
1182     }
1183     else {
1184       ////// selected object belong to the GEOM module
1185       // get interactive object
1186       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1187       objectName = IObject->getName();
1188       // if object has entry get SObject
1189       SALOMEDS::SObject_var SO;
1190       if ( IObject->hasEntry() )
1191         SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1192
1193       if ( theObject == "Component" ) {
1194         ////// menu for component
1195         if ( !isOCCViewer && !isVTKViewer ) {
1196           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1197           popup->removeItem( QAD_Display_Popup_ID );
1198           popup->removeItem( QAD_Erase_Popup_ID );
1199         }
1200       }
1201       else {
1202         ////// not component (should be shape)
1203         if ( IObject->hasEntry() )  /////// VSR : TO BE REMOVED
1204           popup->removeItem( 804 ); // "Add in Study"
1205
1206         // Here could be analysis of the geom shape's type
1207         // ... //
1208
1209         SALOMEDS::GenericAttribute_var aTmpAttr;
1210         if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1211           popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1212
1213         if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1214           if ( theObject == "Shape" )
1215             popup->removeItem( 800 ); // Create Group
1216           else if ( theObject == "Group" )
1217             popup->removeItem( 801 ); // Edit Group
1218         }
1219
1220         if ( isOCCViewer || isVTKViewer ) {
1221           ////// current viewer is OCC or VTK
1222           SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1223           if ( aViewFrame->isVisible( IObject ) ) {
1224             ////// object is already displayed in the viewer
1225             popup->removeItem( QAD_Display_Popup_ID );
1226             if ( isOCCViewer ) {
1227               ////// OCC viewer only
1228               OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1229               if ( occPrs && !occPrs->IsNull() ) {
1230                 AIS_ListOfInteractive ioList;
1231                 occPrs->GetObjects( ioList );
1232                 QMenuItem* mi = popup->findItem( 803 );
1233                 if ( mi && mi->popup() ) {
1234                   if ( ioList.First()->DisplayMode() == 0 )
1235                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1236                   else if ( ioList.First()->DisplayMode() == 1 )
1237                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1238                   else if ( ioList.First()->DisplayMode() < 0 )
1239                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1240                 }
1241               }
1242             }
1243             else {
1244               ////// VTK viewer only
1245               popup->removeItem( 8034 ); // "Isos"
1246               VTKViewer_Prs* vtkPrs = dynamic_cast<VTKViewer_Prs*>( prs );
1247               if ( vtkPrs && !vtkPrs->IsNull() ) {
1248                 vtkActorCollection* actorList = vtkPrs->GetObjects();
1249                 actorList->InitTraversal();
1250                 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1251                 QMenuItem* mi = popup->findItem( 803 );
1252                 if ( ac && mi && mi->popup() ) {
1253                   if ( ac->getDisplayMode() == 0 )
1254                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1255                   else if ( ac->getDisplayMode() == 1 )
1256                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1257                   else
1258                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1259                 }
1260               }
1261             }
1262           }
1263           else {
1264             ////// object is not yet displayed in the viewer
1265             popup->removeItem( 803 );  // "Display Mode"
1266             popup->removeItem( 8032 ); // "Color"
1267             popup->removeItem( 8033 ); // "Transparency"
1268             popup->removeItem( 8034 ); // "Isos"
1269             popup->removeItem( QAD_Erase_Popup_ID );
1270           }
1271           delete prs;
1272         }
1273         else {
1274           ////// other viewer type (neither OCC nor VTK)
1275           popup->removeItem( 803 );  // "Display Mode"
1276           popup->removeItem( 8032 ); // "Color"
1277           popup->removeItem( 8033 ); // "Transparency"
1278           popup->removeItem( 8034 ); // "Isos"
1279           popup->removeItem( QAD_Display_Popup_ID );
1280           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1281           popup->removeItem( QAD_Erase_Popup_ID );
1282         }
1283       }
1284     }
1285   }
1286   else {
1287     ////// MULTIPLE SELECTION
1288     if ( parentComponent != parent->getActiveComponent() )  {
1289       ////// not GEOM module objects or objects belong to different modules
1290       // remove all commands except Display/Erase...
1291       while ( 1 ) {
1292         int id = popup->idAt( 0 );
1293         if ( id <= QAD_TopLabel_Popup_ID )
1294           popup->removeItemAt( 0 );
1295         else
1296           break;
1297       }
1298       if ( parentComponent.isNull() )  {
1299         ////// objects belong to different modules
1300         popup->removeItem(QAD_Display_Popup_ID);
1301         popup->removeItem(QAD_DisplayOnly_Popup_ID);
1302         popup->removeItem(QAD_Erase_Popup_ID);
1303       }
1304       else {
1305         objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1306       }
1307     }
1308     else {
1309       ////// all selected objects belong to GEOM module
1310       popup->removeItem( 901 ); // "Rename"
1311
1312       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1313       bool isComponent  = false;
1314       bool needOpen     = false;
1315       bool needDisplay  = false;
1316       bool needErase    = false;
1317       int needToPublish = 0;
1318
1319       for( ;It.More();It.Next() ) {
1320         Handle(SALOME_InteractiveObject) anIObject = It.Value();
1321
1322         if ( aViewFrame->isVisible( anIObject ) )
1323           needErase   = true;
1324         else
1325           needDisplay = true;
1326
1327         if( anIObject->hasEntry() ) {
1328           needToPublish = -1; /////// VSR : TO BE REMOVED
1329           SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1330           SALOMEDS::GenericAttribute_var aTmpAttr;
1331           if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1332             needOpen = true;  /////// VSR : TO BE REMOVED
1333           if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1334             isComponent = true;
1335         }
1336         else {
1337           if ( needToPublish != -1 ) needToPublish = 1;
1338         }
1339       }
1340       if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1341         ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1342         popup->removeItem( 803 );  // "Display Mode"
1343         popup->removeItem( 8032 ); // "Color"
1344         popup->removeItem( 8033 ); // "Transparency"
1345         popup->removeItem( 8034 ); // "Isos"
1346         popup->removeItem( 804 );  // "Add in Study"
1347         popup->removeItem( QAD_DisplayOnly_Popup_ID );
1348         popup->removeItem( QAD_Display_Popup_ID );
1349         popup->removeItem( QAD_Erase_Popup_ID );
1350       }
1351       else {
1352         popup->removeItem( 9024 );   // "Open"
1353         if ( needToPublish <= 0 )
1354           popup->removeItem( 804 );  // "Add in Study"
1355
1356         if( isComponent ) {
1357           popup->removeItem( 803 );  // "Display Mode"
1358           popup->removeItem( 8032 ); // "Color"
1359           popup->removeItem( 8033 ); // "Transparency"
1360           popup->removeItem( 8034 ); // "Isos"
1361           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1362         }
1363
1364         if ( !needDisplay )
1365           popup->removeItem( QAD_Display_Popup_ID );
1366         if ( !needErase )
1367           popup->removeItem( QAD_Erase_Popup_ID );
1368         if ( !isOCCViewer )
1369           popup->removeItem( 8034 ); // "Isos"
1370       }
1371     }
1372   }
1373
1374   // check popup for unnecessary separators
1375   QAD_Tools::checkPopup( popup );
1376   // find popup menu's TopLabel item (with title)
1377   int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1378   if ( topItem >= 0 ) {
1379     // remove popup menu's title item
1380     popup->removeItem( QAD_TopLabel_Popup_ID );
1381     if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1382       // set bold font for popup menu's title
1383       QFont f = popup->font(); f.setBold( TRUE );
1384       popup->removeItem( QAD_TopLabel_Popup_ID );
1385       popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1386     }
1387   }
1388
1389   return false;
1390 }
1391
1392 */
1393
1394 //=======================================================================
1395 // function : GeometryGUI::BuildPresentation()
1396 // purpose  : 
1397 //=======================================================================
1398 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1399 {
1400   //GEOM_Displayer().Display( io, false, win );
1401 }
1402
1403 //=======================================================================
1404 // function : setCommandsEnabled()
1405 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1406 //=======================================================================
1407 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1408 {
1409   if ( !win )
1410     return;
1411
1412   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1413 //  const bool ViewVTK = ( win->getViewManager()->getType() == VTKViewer_Viewer::Type() );
1414   
1415   // disable non-OCC viewframe menu commands
1416 //  action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1417   action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1418   action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1419   action( 606 )->setEnabled( ViewOCC ); // CloseContour
1420   action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1421   action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1422 //  action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1423   action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1424
1425   action( 800 )->setEnabled( ViewOCC ); // Create Group
1426   action( 801 )->setEnabled( ViewOCC ); // Edit Group
1427
1428   action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1429 }
1430
1431 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1432 {
1433   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1434   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1435 }
1436
1437 void GeometryGUI::viewManagers( QStringList& lst ) const
1438 {
1439   lst.append( OCCViewer_Viewer::Type() );
1440 }
1441
1442 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1443 {
1444   if ( vm->getType() == OCCViewer_Viewer::Type() )
1445   {
1446     SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1447     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1448
1449     // disable OCC selectors
1450     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1451     for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1452       sr->setEnabled(true);
1453   }
1454   else if ( vm->getType() == VTKViewer_Viewer::Type() )
1455   {
1456     SalomeApp_SelectionMgr* sm = getApp()->selectionMgr();
1457     myVTKSelectors.append( new SalomeApp_VTKSelector( (SVTK_Viewer*)vm->getViewModel(), sm ) );
1458     
1459     // disable VTK selectors
1460     getApp()->selectionMgr()->setEnabled( false, VTKViewer_Viewer::Type() );
1461     for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1462       sr->setEnabled(true);
1463   }
1464 }
1465
1466 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1467 {
1468   SUIT_ViewModel* viewer = vm->getViewModel();
1469   if ( vm->getType() == OCCViewer_Viewer::Type() )
1470   {
1471     for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1472       if ( sr->viewer() == viewer )
1473       {
1474         myOCCSelectors.remove( sr );
1475         break;
1476       }
1477   }
1478   if ( vm->getType() == VTKViewer_Viewer::Type() )
1479   {
1480     for ( SalomeApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1481       if ( sr->viewer() == viewer )
1482       {
1483         myVTKSelectors.remove( sr );
1484         break;
1485       }
1486   }
1487 }
1488
1489 QString GeometryGUI::engineIOR() const
1490 {
1491   if ( !CORBA::is_nil( GetGeomGen() ) )
1492     return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1493   return QString( "" );
1494 }
1495
1496 SalomeApp_Selection* GeometryGUI::createSelection() const
1497 {
1498   return new GEOMGUI_Selection();
1499 }
1500
1501 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1502 {
1503   SalomeApp_Module::contextMenuPopup( client, menu, title );
1504   SALOME_ListIO lst;
1505   getApp()->selectionMgr()->selectedObjects( lst );
1506   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1507     Handle(SALOME_InteractiveObject) io = lst.First();
1508     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1509     _PTR(Study) study = appStudy->studyDS();
1510     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1511     if ( obj )
1512       title = QString( obj->GetName().c_str() );
1513   }
1514 }
1515
1516 void GeometryGUI::createPreferences()
1517 {
1518   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1519
1520   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1521   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1522                  SalomeApp_Preferences::Color, "Geometry", "shading_color" );
1523   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1524                             SalomeApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1525   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1526                             SalomeApp_Preferences::Selector, "Geometry", "display_mode" );
1527
1528   setPreferenceProperty( genGroup, "columns", 1 );
1529
1530   setPreferenceProperty( step, "min", 0.001 );
1531   setPreferenceProperty( step, "max", 10000 );
1532   setPreferenceProperty( step, "precision", 3 );
1533
1534   // Set property for default display mode
1535   QStringList aModesList;
1536   aModesList.append( tr("MEN_WIREFRAME") );
1537   aModesList.append( tr("MEN_SHADING") );
1538   
1539   QValueList<QVariant> anIndexesList;
1540   anIndexesList.append(0);
1541   anIndexesList.append(1);
1542   
1543   setPreferenceProperty( dispmode, "strings", aModesList );
1544   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1545 }
1546
1547 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1548 {
1549 }