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