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