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