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