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