]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMGUI/GeometryGUI.cxx
Salome HOME
*** empty log message ***
[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 // File   : GeometryGUI.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 //
25
26 #include "GeometryGUI.h"
27 #include "GEOMGUI_OCCSelector.h"
28 #include "GEOMGUI_Selection.h"
29 #include "GEOM_Displayer.h"
30
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ViewManager.h>
36
37 #include <OCCViewer_ViewWindow.h>
38 #include <OCCViewer_ViewPort3d.h>
39 #include <OCCViewer_ViewModel.h>
40 #include <OCCViewer_ViewManager.h>
41
42 #include <SVTK_ViewWindow.h>
43 #include <SVTK_RenderWindowInteractor.h>
44 #include <SVTK_InteractorStyle.h>
45 #include <SVTK_ViewModel.h>
46
47 #include <SalomeApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_VTKSelector.h>
50 #include <SalomeApp_Study.h>
51 #include <LightApp_Preferences.h>
52 #include <SALOME_LifeCycleCORBA.hxx>
53 #include <SALOME_ListIO.hxx>
54
55 // External includes
56 #include <QAction>
57 #include <QFileInfo>
58 #include <QString>
59 #include <QPainter>
60
61 #include <Prs3d_Drawer.hxx>
62 #include <Prs3d_IsoAspect.hxx>
63 #include <Aspect_TypeOfMarker.hxx>
64 #include <OSD_SharedLibrary.hxx>
65
66 #include <utilities.h>
67
68 #include <vtkCamera.h>
69 #include <vtkRenderer.h>
70
71 using namespace Qt;
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 // function : GeometryGUI::GeometryGUI()
134 // purpose  : Constructor
135 //=======================================================================
136 GeometryGUI::GeometryGUI() :
137   SalomeApp_Module( "GEOM" )
138 {
139   if ( CORBA::is_nil( myComponentGeom ) )
140   {
141     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
142     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
143     myComponentGeom  = GEOM::GEOM_Gen::_narrow( comp );
144   }
145
146   myState           = -1;
147   myActiveDialogBox = 0;
148   myFatherior       = "";
149
150   gp_Pnt origin = gp_Pnt(0., 0., 0.);
151   gp_Dir direction = gp_Dir(0., 0., 1.);
152   myWorkingPlane = gp_Ax3(origin, direction);
153
154   myDisplayer = 0;
155   myLocalSelectionMode = GEOM_ALLOBJECTS;
156 }
157
158 //=======================================================================
159 // function : GeometryGUI::~GeometryGUI()
160 // purpose  : Destructor
161 //=======================================================================
162 GeometryGUI::~GeometryGUI()
163 {
164   while (!myOCCSelectors.isEmpty())
165     delete myOCCSelectors.takeFirst();
166
167   while (!myVTKSelectors.isEmpty())
168     delete myVTKSelectors.takeFirst();
169 }
170
171 //=======================================================================
172 // function : GeometryGUI::getLibrary()
173 // purpose  : get or load GUI library by name [ internal ]
174 //=======================================================================
175 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
176 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
177 {
178   if ( !myGUIMap.contains( libraryName ) ) {
179     // try to load library if it is not loaded yet
180     QString libs;
181 #ifndef WNT
182     libs = getenv( "LD_LIBRARY_PATH" );
183     if( !libs.isEmpty() ) {
184       QStringList dirList = libs.split( ":", QString::SkipEmptyParts ); // skip empty entries
185 #else
186     libs = getenv( "PATH" );
187     if( !libs.isEmpty() ) {
188       QStringList dirList = libs.split( ";", QString::SkipEmptyParts ); // skip empty entries
189 #endif
190       for( int i = dirList.count()-1; i >= 0; i-- ) {
191         QString dir = dirList[ i ];
192         QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
193         if( fi.exists() ) {
194           OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().data() );
195           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
196           if( !res ) {
197             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
198             continue; // continue search further
199           }
200           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
201           if ( osdF != NULL ) {
202             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
203             GEOMGUI* libGUI = (*func)(this);
204             if ( libGUI ) {
205               myGUIMap[ libraryName ] = libGUI;
206               break; // found and loaded!
207             }
208           }
209         }
210       }
211     }
212   }
213   if ( myGUIMap.contains( libraryName ) )
214     // library is successfully loaded
215     return myGUIMap[ libraryName ];
216   return 0;
217 }
218
219 //=======================================================================
220 // function : GeometryGUI::ActiveWorkingPlane()
221 // purpose  : Activate Working Plane View
222 //=======================================================================
223 void GeometryGUI::ActiveWorkingPlane()
224 {
225   gp_Dir DZ = myWorkingPlane.Direction();
226   gp_Dir DY = myWorkingPlane.YDirection();
227
228   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
229   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
230   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
231
232   if( ViewOCC ) {
233     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
234     if ( vw ) {
235       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
236
237       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
238       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
239
240       vw->onViewFitAll();
241     }
242   }
243   else if( ViewVTK ) {
244     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
245     if ( vw ) {
246       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
247
248       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
249       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
250       camera->SetFocalPoint(0,0,0);
251
252       vw->onFitAll();
253     }
254   }
255 }
256
257 //=======================================================================
258 // function : GeometryGUI::SetActiveDialogBox()
259 // purpose  : Set active dialog box
260 //=======================================================================
261 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
262 {
263   myActiveDialogBox = (QDialog*)aDlg;
264 }
265
266 //=======================================================================
267 // function : GeometryGUI::EmitSignalDeactivateDialog()
268 // purpose  : Emit a signal to deactivate the active dialog Box
269 //=======================================================================
270 void GeometryGUI::EmitSignalDeactivateDialog()
271 {
272   emit SignalDeactivateActiveDialog();
273 }
274
275 //=======================================================================
276 // function : GeometryGUI::EmitSignalCloseAllDialogs()
277 // purpose  : Emit a signal to close all non modal dialogs box
278 //=======================================================================
279 void GeometryGUI::EmitSignalCloseAllDialogs()
280 {
281   emit SignalCloseAllDialogs();
282 }
283
284 //=======================================================================
285 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
286 // purpose  : Emit a signal to inform that default real spin box step has
287 //            been changed
288 //=======================================================================
289 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
290 {
291   emit SignalDefaultStepValueChanged(newVal);
292 }
293
294 //=======================================================================
295 // function : GeometryGUI::OnGUIEvent()
296 // purpose  : common slot for all menu/toolbar actions
297 //=======================================================================
298 void GeometryGUI::OnGUIEvent()
299 {
300   const QObject* obj = sender();
301   if ( !obj || !obj->inherits( "QAction" ) )
302     return;
303   int id = actionId((QAction*)obj);
304   if ( id != -1 )
305     OnGUIEvent( id );
306 }
307
308 //=======================================================================
309 // function : GeometryGUI::OnGUIEvent()
310 // purpose  : manage all events on GUI [static]
311 //=======================================================================
312 void GeometryGUI::OnGUIEvent( int id )
313 {
314   SUIT_Application* anApp = application();
315   if (!anApp) return;
316   SUIT_Desktop* desk = anApp->desktop();
317
318   // check type of the active viewframe
319   SUIT_ViewWindow* window = desk->activeWindow();
320   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
321   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
322   // if current viewframe is not of OCC and not of VTK type - return immediately
323   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
324   bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
325   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
326       return;
327
328   // fix for IPAL9103, point 2
329   if ( CORBA::is_nil( GetGeomGen() ) ) {
330     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
331     return;
332   }
333
334   GEOMGUI* library = 0;
335   // try to get-or-load corresponding GUI library
336   if( id == 111  ||  // MENU FILE - IMPORT BREP
337       id == 112  ||  // MENU FILE - IMPORT IGES
338       id == 113  ||  // MENU FILE - IMPORT STEP
339       id == 121  ||  // MENU FILE - EXPORT BREP
340       id == 122  ||  // MENU FILE - EXPORT IGES
341       id == 123  ||  // MENU FILE - EXPORT STEP
342       id == 2171 ||  // POPUP VIEWER - SELECT ONLY - VERTEX
343       id == 2172 ||  // POPUP VIEWER - SELECT ONLY - EDGE
344       id == 2173 ||  // POPUP VIEWER - SELECT ONLY - WIRE
345       id == 2174 ||  // POPUP VIEWER - SELECT ONLY - FACE
346       id == 2175 ||  // POPUP VIEWER - SELECT ONLY - SHELL
347       id == 2176 ||  // POPUP VIEWER - SELECT ONLY - SOLID
348       id == 2177 ||  // POPUP VIEWER - SELECT ONLY - COMPOUND
349       id == 2178 ||  // POPUP VIEWER - SELECT ONLY - SELECT ALL      
350       id == 31   ||  // MENU EDIT - COPY
351       id == 33   ||  // MENU EDIT - DELETE
352       id == 411  ||  // MENU SETTINGS - ADD IN STUDY
353       id == 412  ||  // MENU SETTINGS - SHADING COLOR
354       id == 5103 ||  // MENU TOOLS - CHECK GEOMETRY
355       id == 8032 ||  // POPUP VIEWER - COLOR
356       id == 8033 ||  // POPUP VIEWER - TRANSPARENCY
357       id == 8034 ||  // POPUP VIEWER - ISOS
358       id == 804  ||  // POPUP VIEWER - ADD IN STUDY
359       id == 901  ||  // OBJECT BROWSER - RENAME
360       id == 9024 ) { // OBJECT BROWSER - OPEN
361     //cout << "id " << id << " received" << endl;
362 #ifndef WNT
363         library = getLibrary( "libGEOMToolsGUI.so" );
364 #else
365         library = getLibrary( "GEOMToolsGUI.dll" );
366 #endif
367   }
368   else if( id == 211  ||  // MENU VIEW - WIREFRAME/SHADING
369            id == 212  ||  // MENU VIEW - DISPLAY ALL
370            id == 213  ||  // MENU VIEW - DISPLAY ONLY
371            id == 214  ||  // MENU VIEW - ERASE ALL
372            id == 215  ||  // MENU VIEW - ERASE
373            id == 216  ||  // MENU VIEW - DISPLAY
374            id == 80311 ||  // POPUP VIEWER - WIREFRAME
375            id == 80312 ) { // POPUP VIEWER - SHADING
376 #ifndef WNT
377         library = getLibrary( "libDisplayGUI.so" );
378 #else
379         library = getLibrary( "DisplayGUI.dll" );
380 #endif
381   }
382   else if( id == 4011 ||  // MENU BASIC - POINT
383            id == 4012 ||  // MENU BASIC - LINE
384            id == 4013 ||  // MENU BASIC - CIRCLE
385            id == 4014 ||  // MENU BASIC - ELLIPSE
386            id == 4015 ||  // MENU BASIC - ARC
387            id == 4016 ||  // MENU BASIC - VECTOR
388            id == 4017 ||  // MENU BASIC - PLANE
389            id == 4018 ||  // MENU BASIC - WPLANE
390            id == 4019 ||  // MENU BASIC - CURVE
391            id == 4020 ) { // MENU BASIC - REPAIR
392 #ifndef WNT
393         library = getLibrary( "libBasicGUI.so" );
394 #else
395         library = getLibrary( "BasicGUI.dll" );
396 #endif
397   }
398   else if( id == 4021 ||  // MENU PRIMITIVE - BOX
399            id == 4022 ||  // MENU PRIMITIVE - CYLINDER
400            id == 4023 ||  // MENU PRIMITIVE - SPHERE
401            id == 4024 ||  // MENU PRIMITIVE - TORUS
402            id == 4025 ) { // MENU PRIMITIVE - CONE
403 #ifndef WNT
404         library = getLibrary( "libPrimitiveGUI.so" );
405 #else
406         library = getLibrary( "PrimitiveGUI.dll" );
407 #endif
408   }
409   else if( id == 4031 ||  // MENU GENERATION - PRISM
410            id == 4032 ||  // MENU GENERATION - REVOLUTION
411            id == 4033 ||  // MENU GENERATION - FILLING
412            id == 4034 ) { // MENU GENERATION - PIPE
413 #ifndef WNT
414         library = getLibrary( "libGenerationGUI.so" );
415 #else
416         library = getLibrary( "GenerationGUI.dll" );
417 #endif
418   }
419   else if( id == 404 ||   // MENU ENTITY - SKETCHER
420            id == 407 ) {  // MENU ENTITY - EXPLODE
421 #ifndef WNT
422         library = getLibrary( "libEntityGUI.so" );
423 #else
424         library = getLibrary( "EntityGUI.dll" );
425 #endif
426   }
427   else if( id == 4081 ||  // MENU BUILD - EDGE
428            id == 4082 ||  // MENU BUILD - WIRE
429            id == 4083 ||  // MENU BUILD - FACE
430            id == 4084 ||  // MENU BUILD - SHELL
431            id == 4085 ||  // MENU BUILD - SOLID
432            id == 4086 ) { // MENU BUILD - COMPUND
433 #ifndef WNT
434         library = getLibrary( "libBuildGUI.so" );
435 #else
436         library = getLibrary( "BuildGUI.dll" );
437 #endif
438   }
439   else if( id == 5011 ||  // MENU BOOLEAN - FUSE
440            id == 5012 ||  // MENU BOOLEAN - COMMON
441            id == 5013 ||  // MENU BOOLEAN - CUT
442            id == 5014 ) { // MENU BOOLEAN - SECTION
443 #ifndef WNT
444         library = getLibrary( "libBooleanGUI.so" );
445 #else
446         library = getLibrary( "BooleanGUI.dll" );
447 #endif
448   }
449   else if( id == 5021 ||  // MENU TRANSFORMATION - TRANSLATION
450            id == 5022 ||  // MENU TRANSFORMATION - ROTATION
451            id == 5023 ||  // MENU TRANSFORMATION - LOCATION
452            id == 5024 ||  // MENU TRANSFORMATION - MIRROR
453            id == 5025 ||  // MENU TRANSFORMATION - SCALE
454            id == 5026 ||  // MENU TRANSFORMATION - OFFSET
455            id == 5027 ||  // MENU TRANSFORMATION - MULTI-TRANSLATION
456            id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
457 #ifndef WNT
458         library = getLibrary( "libTransformationGUI.so" );
459 #else
460         library = getLibrary( "TransformationGUI.dll" );
461 #endif
462   }
463   else if( id == 503 ||   // MENU OPERATION - PARTITION
464            id == 504 ||   // MENU OPERATION - ARCHIMEDE
465            id == 505 ||   // MENU OPERATION - FILLET
466            id == 506 ||   // MENU OPERATION - CHAMFER
467            id == 507 ) {  // MENU OPERATION - CLIPPING RANGE
468 #ifndef WNT
469         library = getLibrary( "libOperationGUI.so" );
470 #else
471         library = getLibrary( "OperationGUI.dll" );
472 #endif
473   }
474   else if( id == 601 ||   // MENU REPAIR - SEWING
475            id == 603 ||   // MENU REPAIR - SUPPRESS FACES
476            id == 604 ||   // MENU REPAIR - SUPPRESS HOLE
477            id == 605 ||   // MENU REPAIR - SHAPE PROCESSING
478            id == 606 ||   // MENU REPAIR - CLOSE CONTOUR
479            id == 607 ||   // MENU REPAIR - REMOVE INTERNAL WIRES
480            id == 608 ||   // MENU REPAIR - ADD POINT ON EDGE
481            id == 609 ||   // MENU REPAIR - FREE BOUNDARIES
482            id == 610 ||   // MENU REPAIR - FREE FACES
483            id == 611 ||   // MENU REPAIR - CHANGE ORIENTATION
484            id == 602 ) {  // MENU REPAIR - GLUE FACES
485 #ifndef WNT
486         library = getLibrary( "libRepairGUI.so" );
487 #else
488         library = getLibrary( "RepairGUI.dll" );
489 #endif
490   }
491   else if( id == 701   ||  // MENU MEASURE - PROPERTIES
492            id == 702   ||  // MENU MEASURE - CDG
493            id == 703   ||  // MENU MEASURE - INERTIA
494            id == 7041  ||  // MENU MEASURE - BOUNDING BOX
495            id == 7042  ||  // MENU MEASURE - MIN DISTANCE
496            id == 705   ||  // MENU MEASURE - TOLERANCE
497            id == 706   ||  // MENU MEASURE - WHATIS
498            id == 707   ||  // MENU MEASURE - CHECK
499            id == 7072  ||  // MENU MEASURE - CHECK COMPOUND OF BLOCKS
500            id == 708 ) {  // MENU MEASURE - POINT COORDINATES
501 #ifndef WNT
502         library = getLibrary( "libMeasureGUI.so" );
503 #else
504         library = getLibrary( "MeasureGUI.dll" );
505 #endif
506   }
507   else if( id == 800  ||  // MENU GROUP - CREATE
508            id == 8001 ||  // POPUP MENU - CREATE GROUP
509            id == 801 ) {  // MENU GROUP - EDIT
510 #ifndef WNT
511         library = getLibrary( "libGroupGUI.so" );
512 #else
513         library = getLibrary( "GroupGUI.dll" );
514 #endif
515   }
516   else if( id == 9999  ||  // MENU BLOCKS - HEXAHEDRAL SOLID
517            id == 9998  ||  // MENU BLOCKS - MULTI-TRANSFORMATION
518            id == 9997  ||  // MENU BLOCKS - QUADRANGLE FACE
519            id == 99991 ||  // MENU BLOCKS - PROPAGATE
520            id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
521 #ifndef WNT
522         library = getLibrary( "libBlocksGUI.so" );
523 #else
524         library = getLibrary( "BlocksGUI.dll" );
525 #endif
526   }
527
528   // call method of corresponding GUI library
529   if ( library )
530     library->OnGUIEvent( id, desk );
531   else
532     SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
533 }
534
535
536 //=================================================================================
537 // function : GeometryGUI::OnKeyPress()
538 // purpose  : Called when any key is pressed by user [static]
539 //=================================================================================
540 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
541 {
542   GUIMap::Iterator it;
543   bool bOk = true;
544   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
545     SUIT_Application* anApp = application();
546     if (!anApp) return;
547     bOk = bOk && it.value()->OnKeyPress( pe, anApp->desktop(), win );
548   }
549 //  return bOk;
550 }
551
552
553 //=================================================================================
554 // function : GeometryGUI::OnMouseMove()
555 // purpose  : Manages mouse move events [static]
556 //=================================================================================
557 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
558 {
559   GUIMap::Iterator it;
560   bool bOk = true;
561   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
562     SUIT_Application* anApp = application();
563     if (!anApp) return;
564     bOk = bOk && it.value()->OnMouseMove( pe, anApp->desktop(), win );
565   }
566 //  return bOk;
567 }
568
569
570 //=================================================================================
571 // function : GeometryGUI::0nMousePress()
572 // purpose  : Manage mouse press events [static]
573 //=================================================================================
574 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
575 {
576   GUIMap::Iterator it;
577   // OnMousePress() should return false if this event should be processed further
578   // (see OCCViewer_Viewer3d::onMousePress() for explanation)
579   bool processed = false;
580   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
581     SUIT_Application* anApp = application();
582     if (!anApp) return;
583     processed = processed || it.value()->OnMousePress( pe, anApp->desktop(), win );
584   }
585 //  return processed;
586 }
587
588 /*
589 static void UpdateVtkSelection()
590 {
591   QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
592   SUIT_ViewWindow* win = 0;
593   for ( win = winList.first(); win; win = winList.next() ) {
594     if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
595       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
596       if ( vw ) {
597         SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
598         anInteractor->SetSelectionProp();
599         anInteractor->SetSelectionTolerance();
600         SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
601         if (aStyle) {
602           aStyle->setPreselectionProp();
603         }
604       }
605     }
606   }
607 }
608
609 //=================================================================================
610 // function : GeometryGUI::SetSettings()
611 // purpose  : Called when GEOM module is activated [static]
612 //=================================================================================
613 bool GeometryGUI::SetSettings()
614 {
615   QMenuBar*     Mb = parent->getMainMenuBar();
616   SUIT_Study*   ActiveStudy = application()->activeStudy();
617
618 // Wireframe or Shading
619   int DisplayMode = 0;
620   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
621   bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
622   bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
623   if ( ViewOCC ) {
624     OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
625     if ( vm ) {
626       Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
627       DisplayMode = ic->DisplayMode();
628     }
629   }
630   else if ( ViewVTK ) {
631     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
632     if ( vw ) {
633       SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
634       DisplayMode = myRenderInter->GetDisplayMode();
635     }
636   }
637
638   if( DisplayMode == 1 )
639     getApp()->
640     Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
641   else
642     Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
643
644
645   // Add in Study  - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
646   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
647   int Settings_AddInStudy;
648   //  if(!AddInStudy.isEmpty())
649   //    Settings_AddInStudy = AddInStudy.toInt();
650   //  else
651
652   Settings_AddInStudy = 1;
653   Mb->setItemChecked(411, Settings_AddInStudy);
654
655   // step value
656   QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
657   if(S.isEmpty())
658     QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
659
660   // isos
661   int count = ActiveStudy->getStudyFramesCount();
662   for(int i = 0; i < count; i++) {
663     if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
664       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
665       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
666
667       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
668       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
669       if(!IsoU.isEmpty())
670         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
671       if(!IsoV.isEmpty())
672         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
673     }
674   }
675
676   setActionsEnabled();
677
678   // PAL5356: update VTK selection
679   ::UpdateVtkSelection();
680   bool bOk = true;
681   GUIMap::Iterator it;
682   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
683     bOk = bOk && it.data()->SetSettings( parent );
684
685   // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
686   if (getenv( "GEOM_CLIPPING" ) == NULL)
687     {
688       QMenuItem* mi = Mb->findItem(50);
689       if (mi && mi->popup())
690       mi->popup()->removeItem(507);
691     }
692
693   return bOk;
694 }
695 */
696
697 //=======================================================================
698 // function : createGeomAction
699 // purpose  :
700 //=======================================================================
701 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
702 {
703   QIcon icon;
704   QWidget* parent = application()->desktop();
705   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
706   QPixmap pix;
707   if ( icon_id.length() )
708     pix = resMgr->loadPixmap( "GEOM", tr( icon_id.toLatin1().constData() ) );
709   else
710     pix = resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+po_id).toLatin1().constData() ), false );
711   if ( !pix.isNull() )
712     icon = QIcon( pix );
713
714   QString tooltip    = tr( (QString( "TOP_" )+po_id).toLatin1().constData() ),
715           menu       = tr( (QString( "MEN_" )+po_id).toLatin1().constData() ),
716           status_bar = tr( (QString( "STB_" )+po_id).toLatin1().constData() );
717
718   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
719 }
720
721
722
723 //=======================================================================
724 // function : GeometryGUI::initialize()
725 // purpose  : Called when GEOM module is created
726 //=======================================================================
727 void GeometryGUI::initialize( CAM_Application* app )
728 {
729   SalomeApp_Module::initialize( app );
730
731   // ----- create actions --------------
732
733   createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
734   createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
735
736   createGeomAction( 33, "DELETE" );
737
738   createGeomAction( 4011, "POINT" );
739   createGeomAction( 4012, "LINE" );
740   createGeomAction( 4013, "CIRCLE" );
741   createGeomAction( 4014, "ELLIPSE" );
742   createGeomAction( 4015, "ARC" );
743   createGeomAction( 4019, "CURVE" );
744   createGeomAction( 4016, "VECTOR" );
745   createGeomAction( 4017, "PLANE" );
746   createGeomAction( 4018, "WORK_PLANE" );
747   createGeomAction( 4020, "LOCAL_CS" );
748
749   createGeomAction( 4021, "BOX" );
750   createGeomAction( 4022, "CYLINDER" );
751   createGeomAction( 4023, "SPHERE" );
752   createGeomAction( 4024, "TORUS" );
753   createGeomAction( 4025, "CONE" );
754
755   createGeomAction( 4031, "EXTRUSION" );
756   createGeomAction( 4032, "REVOLUTION" );
757   createGeomAction( 4033, "FILLING" );
758   createGeomAction( 4034, "PIPE" );
759
760   createGeomAction( 800, "GROUP_CREATE" );
761   createGeomAction( 801, "GROUP_EDIT" );
762
763   createGeomAction( 9997, "Q_FACE" );
764   createGeomAction( 9999, "HEX_SOLID" );
765
766   createGeomAction( 404, "SKETCH" );
767   createGeomAction( 407, "EXPLODE" );
768
769   createGeomAction( 4081, "EDGE" );
770   createGeomAction( 4082, "WIRE" );
771   createGeomAction( 4083, "FACE" );
772   createGeomAction( 4084, "SHELL" );
773   createGeomAction( 4085, "SOLID" );
774   createGeomAction( 4086, "COMPOUND" );
775
776   createGeomAction( 5011, "FUSE" );
777   createGeomAction( 5012, "COMMON" );
778   createGeomAction( 5013, "CUT" );
779   createGeomAction( 5014, "SECTION" );
780
781   createGeomAction( 5021, "TRANSLATION" );
782   createGeomAction( 5022, "ROTATION" );
783   createGeomAction( 5023, "MODIFY_LOCATION" );
784   createGeomAction( 5024, "MIRROR" );
785   createGeomAction( 5025, "SCALE" );
786   createGeomAction( 5026, "OFFSET" );
787   createGeomAction( 5027, "MUL_TRANSLATION" );
788   createGeomAction( 5028, "MUL_ROTATION" );
789
790   createGeomAction( 503, "PARTITION" );
791   createGeomAction( 504, "ARCHIMEDE" );
792   createGeomAction( 505, "FILLET" );
793   createGeomAction( 506, "CHAMFER" );
794   //createGeomAction( 507, "CLIPPING" );
795
796   createGeomAction( 9998, "MUL_TRANSFORM" );
797   createGeomAction( 9995, "EXPLODE_BLOCKS" );
798   createGeomAction( 99991, "PROPAGATE" );
799
800   createGeomAction( 601, "SEWING" );
801   createGeomAction( 602, "GLUE_FACES" );
802   createGeomAction( 603, "SUPPRESS_FACES" );
803   createGeomAction( 604, "SUPPERSS_HOLES" );
804   createGeomAction( 605, "SHAPE_PROCESS" );
805   createGeomAction( 606, "CLOSE_CONTOUR" );
806   createGeomAction( 607, "SUPPRESS_INT_WIRES" );
807   createGeomAction( 608, "POINT_ON_EDGE" );
808   createGeomAction( 609, "CHECK_FREE_BNDS" );
809   createGeomAction( 610, "CHECK_FREE_FACES" );
810   createGeomAction( 611, "CHANGE_ORIENTATION" );
811
812   createGeomAction( 708, "POINT_COORDS" );
813   createGeomAction( 701, "BASIC_PROPS" );
814   createGeomAction( 702, "MASS_CENTER" );
815   createGeomAction( 703, "INERTIA" );
816   createGeomAction( 7041, "BND_BOX" );
817   createGeomAction( 7042, "MIN_DIST" );
818
819   createGeomAction( 705, "TOLERANCE" );
820   createGeomAction( 706, "WHAT_IS" );
821   createGeomAction( 707, "CHECK" );
822   createGeomAction( 7072, "CHECK_COMPOUND" );
823
824   createGeomAction( 5103, "CHECK_GEOMETRY" );
825
826   createGeomAction( 412, "SHADING_COLOR" );
827
828   createGeomAction( 211, "SHADING" );
829   createGeomAction( 212, "DISPLAY_ALL" );
830   createGeomAction( 214, "ERASE_ALL" );
831   createGeomAction( 216, "DISPLAY" );
832   createGeomAction( 2171, "VERTEX_SEL_ONLY" ,"", 0, true );
833   createGeomAction( 2172, "EDGE_SEL_ONLY", "", 0, true );
834   createGeomAction( 2173, "WIRE_SEL_ONLY", "",  0, true );
835   createGeomAction( 2174, "FACE_SEL_ONLY", "", 0, true );
836   createGeomAction( 2175, "SHELL_SEL_ONLY", "",  0, true );
837   createGeomAction( 2176, "SOLID_SEL_ONLY", "", 0, true );
838   createGeomAction( 2177, "COMPOUND_SEL_ONLY", "",  0, true );
839   createGeomAction( 2178, "ALL_SEL_ONLY", "",  0, true );
840   createGeomAction( 213, "DISPLAY_ONLY" );
841   createGeomAction( 215, "ERASE" );
842
843   createGeomAction( 901, "POP_RENAME" );
844   createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
845   createGeomAction( 80312, "POP_SHADING", "", 0, true );
846   createGeomAction( 8032, "POP_COLOR" );
847   createGeomAction( 8033, "POP_TRANSPARENCY" );
848   createGeomAction( 8034, "POP_ISOS" );
849   createGeomAction( 8001, "POP_CREATE_GROUP" );
850
851   // make wireframe-shading items to be exclusive (only one at a time is selected)
852   //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
853   //dispModeGr->add( action( 80311 ) );
854   //dispModeGr->add( action( 80312 ) );
855   // ---- create menu --------------------------
856
857   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
858   createMenu( separator(), fileId, 10 );
859   createMenu( 111, fileId, 10 );
860   createMenu( 121, fileId, 10 );
861   createMenu( separator(), fileId, -1 );
862
863   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
864   createMenu( 33, editId, -1 );
865
866   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
867
868   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
869   createMenu( 4011, basicId, -1 );
870   createMenu( 4012, basicId, -1 );
871   createMenu( 4013, basicId, -1 );
872   createMenu( 4014, basicId, -1 );
873   createMenu( 4015, basicId, -1 );
874   createMenu( 4019, basicId, -1 );
875   createMenu( separator(), basicId, -1 );
876   createMenu( 4016, basicId, -1 );
877   createMenu( 4017, basicId, -1 );
878   createMenu( 4018, basicId, -1 );
879   createMenu( 4020, basicId, -1 );
880
881   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
882   createMenu( 4021, primId, -1 );
883   createMenu( 4022, primId, -1 );
884   createMenu( 4023, primId, -1 );
885   createMenu( 4024, primId, -1 );
886   createMenu( 4025, primId, -1 );
887
888   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
889   createMenu( 4031, genId, -1 );
890   createMenu( 4032, genId, -1 );
891   createMenu( 4033, genId, -1 );
892   createMenu( 4034, genId, -1 );
893   createMenu( separator(), newEntId, -1 );
894
895   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
896   createMenu( 800, groupId, -1 );
897   createMenu( 801, groupId, -1 );
898   createMenu( separator(), newEntId, -1 );
899
900   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
901   createMenu( 9997, blocksId, -1 );
902   createMenu( 9999, blocksId, -1 );
903
904   createMenu( separator(), newEntId, -1 );
905   createMenu( 404, newEntId, -1 );
906   createMenu( separator(), newEntId, -1 );
907   createMenu( 407, newEntId, -1 );
908
909   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
910   createMenu( 4081, buildId, -1 );
911   createMenu( 4082, buildId, -1 );
912   createMenu( 4083, buildId, -1 );
913   createMenu( 4084, buildId, -1 );
914   createMenu( 4085, buildId, -1 );
915   createMenu( 4086, buildId, -1 );
916
917   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
918
919   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
920   createMenu( 5011, boolId, -1 );
921   createMenu( 5012, boolId, -1 );
922   createMenu( 5013, boolId, -1 );
923   createMenu( 5014, boolId, -1 );
924
925   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
926   createMenu( 5021, transId, -1 );
927   createMenu( 5022, transId, -1 );
928   createMenu( 5023, transId, -1 );
929   createMenu( 5024, transId, -1 );
930   createMenu( 5025, transId, -1 );
931   createMenu( 5026, transId, -1 );
932   createMenu( separator(), transId, -1 );
933   createMenu( 5027, transId, -1 );
934   createMenu( 5028, transId, -1 );
935
936   createMenu( 503, operId, -1 );
937   createMenu( 504, operId, -1 );
938   createMenu( separator(), operId, -1 );
939   createMenu( 505, transId, -1 );
940   createMenu( 506, transId, -1 );
941   //createMenu( 507, transId, -1 );
942
943   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
944   createMenu( 9998, blockId, -1 );
945   createMenu( 9995, blockId, -1 );
946   createMenu( 99991, blockId, -1 );
947
948   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
949   createMenu( 605, repairId, -1 );
950   createMenu( 603, repairId, -1 );
951   createMenu( 606, repairId, -1 );
952   createMenu( 607, repairId, -1 );
953   createMenu( 604, repairId, -1 );
954   createMenu( 601, repairId, -1 );
955   createMenu( 602, repairId, -1 );
956   createMenu( 608, repairId, -1 );
957   createMenu( 609, repairId, -1 );
958   createMenu( 610, repairId, -1 );
959   createMenu( 611, repairId, -1 );
960
961   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
962   createMenu( 708, measurId, -1 );
963   createMenu( 701, measurId, -1 );
964   createMenu( separator(), measurId, -1 );
965   createMenu( 702, measurId, -1 );
966   createMenu( 703, measurId, -1 );
967   createMenu( separator(), measurId, -1 );
968
969   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
970   createMenu( 7041, dimId, -1 );
971   createMenu( 7042, dimId, -1 );
972   createMenu( separator(), measurId, -1 );
973
974   createMenu( 705, measurId, -1 );
975   createMenu( separator(), measurId, -1 );
976   createMenu( 706, measurId, -1 );
977   createMenu( 707, measurId, -1 );
978   createMenu( 7072, measurId, -1 );
979
980   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
981   createMenu( separator(), toolsId, -1 );
982   createMenu( 5103, toolsId, -1 );
983
984   //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
985   //createMenu( separator(), prefId, -1 );
986   //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
987   //createMenu( 412, geomId, -1 );
988   //createMenu( separator(), prefId, -1 );
989
990   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
991   createMenu( separator(), viewId, -1 );
992
993   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
994   createMenu( 211, dispmodeId, -1 );
995
996   createMenu( separator(), viewId, -1 );
997   createMenu( 212, viewId, -1 );
998   createMenu( 214, viewId, -1 );
999   createMenu( separator(), viewId, -1 );
1000
1001 /*
1002   PAL9111:
1003   because of these items are accessible through object browser and viewers
1004   we have removed they from main menu
1005
1006   createMenu( 216, viewId, -1 );
1007   createMenu( 213, viewId, -1 );
1008   createMenu( 215, viewId, -1 );
1009 */
1010
1011   // ---- create toolbars --------------------------
1012
1013   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1014   createTool( 4011, basicTbId );
1015   createTool( 4012, basicTbId );
1016   createTool( 4013, basicTbId );
1017   createTool( 4014, basicTbId );
1018   createTool( 4015, basicTbId );
1019   createTool( 4019, basicTbId );
1020   createTool( 4016, basicTbId );
1021   createTool( 4017, basicTbId );
1022   createTool( 4018, basicTbId );
1023   createTool( 4020, basicTbId );
1024
1025   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1026   createTool( 4021, primTbId );
1027   createTool( 4022, primTbId );
1028   createTool( 4023, primTbId );
1029   createTool( 4024, primTbId );
1030   createTool( 4025, primTbId );
1031
1032   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1033   createTool( 5011, boolTbId );
1034   createTool( 5012, boolTbId );
1035   createTool( 5013, boolTbId );
1036   createTool( 5014, boolTbId );
1037
1038   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1039   createTool( 4031, genTbId );
1040   createTool( 4032, genTbId );
1041   createTool( 4033, genTbId );
1042   createTool( 4034, genTbId );
1043
1044   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1045   createTool( 5021, transTbId );
1046   createTool( 5022, transTbId );
1047   createTool( 5023, transTbId );
1048   createTool( 5024, transTbId );
1049   createTool( 5025, transTbId );
1050   createTool( 5026, transTbId );
1051   createTool( separator(), transTbId );
1052   createTool( 5027, transTbId );
1053   createTool( 5028, transTbId );
1054
1055   // ---- create popup menus --------------------------
1056
1057   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1058   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1059
1060   QtxPopupMgr* mgr = popupMgr();
1061   mgr->insert( action(  901 ), -1, -1 );  // rename
1062   mgr->setRule( action( 901 ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1063   mgr->insert( action(  8001 ), -1, -1 ); // create group
1064   mgr->setRule( action( 8001 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1065   mgr->insert( action(  801 ), -1, -1 );  // edit group
1066   mgr->setRule( action( 801 ),  QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1067   mgr->insert( separator(), -1, -1 );     // -----------
1068   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1069   mgr->insert( action(  80311 ), dispmodeId, -1 ); // wireframe
1070   mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1071   mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1072   mgr->insert( action(  80312 ), dispmodeId, -1 ); // shading
1073   mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1074   mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1075   mgr->insert( separator(), -1, -1 );     // -----------
1076   mgr->insert( action(  8032 ), -1, -1 ); // color
1077   mgr->setRule( action( 8032 ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1078   mgr->insert( action(  8033 ), -1, -1 ); // transparency
1079   mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1080   mgr->insert( action(  8034 ), -1, -1 ); // isos
1081   mgr->setRule( action( 8034 ), QString("client='OCCViewer' and selcount>0 and isVisible"), QtxPopupMgr::VisibleRule );
1082   mgr->insert( separator(), -1, -1 );     // -----------
1083
1084
1085   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1086           onlyComponent = "((type='Component') and selcount=1)",
1087           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1088           types = "'Shape' 'Group'";
1089
1090   mgr->insert( action(  216 ), -1, -1 ); // display
1091   mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1092
1093   mgr->insert( action(  215 ), -1, -1 ); // erase
1094   mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1095
1096   mgr->insert( action(  214 ), -1, -1 ); // erase All
1097   mgr->setRule( action( 214 ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1098
1099   QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1100   
1101   int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1);                //select only menu
1102   mgr->insert( action(2171), selectolnyId, -1);                                  //Vertex
1103   mgr->setRule(action(2171), selectOnly, QtxPopupMgr::VisibleRule);
1104   mgr->setRule(action(2171), selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1105   mgr->insert( action(2172), selectolnyId, -1);                                  //Edge
1106   mgr->setRule(action(2172), selectOnly, QtxPopupMgr::VisibleRule);
1107   mgr->setRule(action(2172), selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1108   mgr->insert( action(2173), selectolnyId, -1);                                  //Wire
1109   mgr->setRule(action(2173), selectOnly, QtxPopupMgr::VisibleRule);
1110   mgr->setRule(action(2173), selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1111   mgr->insert( action(2174), selectolnyId, -1);                                  //Face
1112   mgr->setRule(action(2174), selectOnly, QtxPopupMgr::VisibleRule);
1113   mgr->setRule(action(2174), selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1114   mgr->insert( action(2175), selectolnyId, -1);                                  //Shell
1115   mgr->setRule(action(2175), selectOnly, QtxPopupMgr::VisibleRule);
1116   mgr->setRule(action(2175), selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1117   mgr->insert( action(2176), selectolnyId, -1);                                  //Solid
1118   mgr->setRule(action(2176), selectOnly, QtxPopupMgr::VisibleRule);
1119   mgr->setRule(action(2176), selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1120   mgr->insert( action(2177), selectolnyId, -1);                                  //Compound
1121   mgr->setRule(action(2177), selectOnly, QtxPopupMgr::VisibleRule);
1122   mgr->setRule(action(2177), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1123   mgr->insert( separator(), selectolnyId, -1);
1124   mgr->insert( action(2178), selectolnyId, -1);                                  //Clear selection filter
1125   mgr->setRule(action(2178), selectOnly, QtxPopupMgr::VisibleRule);
1126   mgr->setRule(action(2178), selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1127   
1128   mgr->insert( action(  213 ), -1, -1 ); // display only
1129   mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1130   mgr->insert( separator(), -1, -1 );
1131
1132   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1133 }
1134
1135 //=======================================================================
1136 // function : GeometryGUI::activateModule()
1137 // purpose  : Called when GEOM module is activated
1138 //=======================================================================
1139 bool GeometryGUI::activateModule( SUIT_Study* study )
1140 {
1141   if ( CORBA::is_nil( myComponentGeom ) )
1142     return false;
1143
1144   bool res = SalomeApp_Module::activateModule( study );
1145
1146   if ( !res )
1147     return false;
1148
1149   setMenuShown( true );
1150   setToolShown( true );
1151
1152   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1153           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1154
1155   // Reset actions accelerator keys
1156   //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1157   //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1158   action(111)->setEnabled(true); // Import
1159   action(121)->setEnabled(true); // Export
1160
1161   GUIMap::Iterator it;
1162   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1163     it.value()->activate( application()->desktop() );
1164
1165   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1166   SUIT_ViewManager* vm;
1167   ViewManagerList OCCViewManagers, VTKViewManagers;
1168
1169   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1170   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1171   while ( itOCC.hasNext() && (vm = itOCC.next()) )
1172     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1173
1174   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1175   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1176   while ( itVTK.hasNext() && (vm = itVTK.next()) )
1177     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1178
1179   // disable OCC selectors
1180   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1181   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1182   while ( itOCCSel.hasNext() )
1183     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1184       sr->setEnabled(true);
1185   
1186   // disable VTK selectors
1187   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1188   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1189   while ( itVTKSel.hasNext() )
1190     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1191       sr->setEnabled(true);
1192
1193   return true;
1194 }
1195
1196
1197 //=======================================================================
1198 // function : GeometryGUI::deactivateModule()
1199 // purpose  : Called when GEOM module is deactivated
1200 //=======================================================================
1201 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1202 {
1203   setMenuShown( false );
1204   setToolShown( false );
1205
1206   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1207              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1208
1209   EmitSignalCloseAllDialogs();
1210
1211   GUIMap::Iterator it;
1212   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1213     it.value()->deactivate();
1214
1215   // Unset actions accelerator keys
1216   //action(111)->setAccel(QKeySequence()); // Import
1217   //action(121)->setAccel(QKeySequence()); // Export
1218   action(111)->setEnabled(false); // Import
1219   action(121)->setEnabled(false); // Export
1220
1221   myOCCSelectors.clear();
1222   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1223
1224   myVTKSelectors.clear();
1225   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1226
1227   return SalomeApp_Module::deactivateModule( study );
1228 }
1229
1230 //=======================================================================
1231 // function : GeometryGUI::BuildPresentation()
1232 // purpose  :
1233 //=======================================================================
1234 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1235 {
1236   //GEOM_Displayer().Display( io, false, win );
1237 }
1238
1239 //=======================================================================
1240 // function : onWindowActivated()
1241 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1242 //=======================================================================
1243 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1244 {
1245   if ( !win )
1246     return;
1247
1248   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1249 //  const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1250
1251   // disable non-OCC viewframe menu commands
1252 //  action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1253   action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1254   action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1255   action( 606 )->setEnabled( ViewOCC ); // CloseContour
1256   action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1257   action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1258 //  action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1259
1260   action( 800 )->setEnabled( ViewOCC ); // Create Group
1261   action( 801 )->setEnabled( ViewOCC ); // Edit Group
1262
1263   action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1264 }
1265
1266 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1267 {
1268   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1269   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1270 }
1271
1272 void GeometryGUI::viewManagers( QStringList& lst ) const
1273 {
1274   lst.append( OCCViewer_Viewer::Type() );
1275 }
1276
1277 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1278 {
1279   if ( vm->getType() == OCCViewer_Viewer::Type() )
1280   {
1281     qDebug( "connect" );
1282     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1283              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1284     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1285              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1286     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1287              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1288
1289
1290     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1291     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1292
1293     // disable OCC selectors
1294     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1295     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1296     while ( itOCCSel.hasNext() )
1297       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1298         sr->setEnabled(true);
1299   }
1300   else if ( vm->getType() == SVTK_Viewer::Type() )
1301   {
1302     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1303     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1304
1305     // disable VTK selectors
1306     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1307     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1308     while ( itVTKSel.hasNext() )
1309       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1310         sr->setEnabled(true);
1311   }
1312 }
1313
1314 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1315 {
1316   SUIT_ViewModel* viewer = vm->getViewModel();
1317   if ( vm->getType() == OCCViewer_Viewer::Type() )
1318   {
1319     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1320     while ( itOCCSel.hasNext() )
1321       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1322         if ( sr->viewer() == viewer )
1323         {
1324           delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1325           break;
1326         }
1327   }
1328   if ( vm->getType() == SVTK_Viewer::Type() )
1329   {
1330     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1331     while ( itVTKSel.hasNext() )
1332       if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1333         if ( sr->viewer() == viewer )
1334         {
1335           delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1336           break;
1337         }
1338   }
1339 }
1340
1341 QString GeometryGUI::engineIOR() const
1342 {
1343   QString anIOR = QString::null;
1344   if ( !CORBA::is_nil( GetGeomGen() ) )
1345   {
1346     CORBA::String_var objStr = getApp()->orb()->object_to_string( GetGeomGen() );
1347     anIOR = QString( objStr.in() );
1348 //    free( objStr ); ASV : 26.07.06 : commented out because it raises exception and blocks application
1349   }
1350   return anIOR;
1351 }
1352
1353 LightApp_Selection* GeometryGUI::createSelection( const QString& client, LightApp_SelectionMgr* mgr ) const
1354 {
1355   return new GEOMGUI_Selection( client, mgr );
1356 }
1357
1358 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1359 {
1360   SalomeApp_Module::contextMenuPopup( client, menu, title );
1361   SALOME_ListIO lst;
1362   getApp()->selectionMgr()->selectedObjects( lst );
1363   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1364     Handle(SALOME_InteractiveObject) io = lst.First();
1365     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1366     _PTR(Study) study = appStudy->studyDS();
1367     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1368     if ( obj )
1369       title = QString( obj->GetName().c_str() );
1370   }
1371 }
1372
1373 void GeometryGUI::createPreferences()
1374 {
1375   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1376
1377   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1378   setPreferenceProperty( genGroup, "columns", 1 );
1379
1380   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1381                                 LightApp_Preferences::Selector, 
1382                                 "Geometry", "display_mode" );
1383
1384   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1385                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1386
1387   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1388                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1389
1390   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1391                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1392
1393   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1394                  LightApp_Preferences::Color, "Geometry", "line_color" );
1395
1396   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1397                  LightApp_Preferences::Color, "Geometry", "point_color" );
1398
1399   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1400                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1401
1402   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1403                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1404
1405   int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1406
1407   int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1408                                     LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1409
1410   int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1411                                    LightApp_Preferences::DblSpin, "Geometry", "marker_scale" );
1412
1413   // Set property for default display mode
1414   QStringList aModesList;
1415   aModesList.append( tr("MEN_WIREFRAME") );
1416   aModesList.append( tr("MEN_SHADING") );
1417
1418   QList<QVariant> anIndexesList;
1419   anIndexesList.append(0);
1420   anIndexesList.append(1);
1421
1422   setPreferenceProperty( dispmode, "strings", aModesList );
1423   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1424
1425   // Set property for step value for spinboxes
1426   setPreferenceProperty( step, "min", 0.001 );
1427   setPreferenceProperty( step, "max", 10000 );
1428   setPreferenceProperty( step, "precision", 3 );
1429
1430   // Set property for type of vertex marker
1431   QStringList aTypeOfMarkerList;
1432   QList<QVariant> anTypeOfMarkerIndexesList;
1433
1434   aTypeOfMarkerList.append( tr("TOM_PLUS") );
1435   anTypeOfMarkerIndexesList.append(Aspect_TOM_PLUS);
1436
1437   aTypeOfMarkerList.append( tr("TOM_POINT") );
1438   anTypeOfMarkerIndexesList.append(Aspect_TOM_POINT);
1439
1440   aTypeOfMarkerList.append( tr("TOM_STAR") );
1441   anTypeOfMarkerIndexesList.append(Aspect_TOM_STAR);
1442
1443   aTypeOfMarkerList.append( tr("TOM_O") );
1444   anTypeOfMarkerIndexesList.append(Aspect_TOM_O);
1445
1446   aTypeOfMarkerList.append( tr("TOM_X") );
1447   anTypeOfMarkerIndexesList.append(Aspect_TOM_X);
1448
1449   aTypeOfMarkerList.append( tr("TOM_O_POINT") );
1450   anTypeOfMarkerIndexesList.append(Aspect_TOM_O_POINT);
1451
1452   aTypeOfMarkerList.append( tr("TOM_O_PLUS") );
1453   anTypeOfMarkerIndexesList.append(Aspect_TOM_O_PLUS);
1454
1455   aTypeOfMarkerList.append( tr("TOM_O_STAR") );
1456   anTypeOfMarkerIndexesList.append(Aspect_TOM_O_STAR);
1457
1458   aTypeOfMarkerList.append( tr("TOM_O_X") );
1459   anTypeOfMarkerIndexesList.append(Aspect_TOM_O_X);
1460
1461
1462   setPreferenceProperty( typeOfMarker, "strings", aTypeOfMarkerList );
1463   setPreferenceProperty( typeOfMarker, "indexes", anTypeOfMarkerIndexesList );
1464
1465   // Set property for Vertex Marker scale
1466   setPreferenceProperty( markerScale, "min", 1. );
1467   setPreferenceProperty( markerScale, "max", 7. );
1468   setPreferenceProperty( markerScale, "precision", 0.01 );
1469   setPreferenceProperty( markerScale, "step", 0.5 );
1470
1471 }
1472
1473 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1474 {
1475   if (section == "Geometry") {
1476     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1477     if (param == QString("SettingsGeomStep")) {
1478       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1479       EmitSignalDefaultStepValueChanged(spin_step);
1480     }
1481   }
1482 }
1483
1484 LightApp_Displayer* GeometryGUI::displayer()
1485 {
1486   if( !myDisplayer )
1487     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1488   return myDisplayer;
1489 }
1490
1491 void GeometryGUI::setLocalSelectionMode(const int mode)
1492 {
1493   myLocalSelectionMode = mode;
1494 }
1495 int GeometryGUI::getLocalSelectionMode() const
1496 {
1497   return myLocalSelectionMode;
1498 }