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