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