1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GeometryGUI.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "GeometryGUI.h"
27 #include "GEOMGUI_OCCSelector.h"
28 #include "GEOMGUI_Selection.h"
29 #include "GEOM_Displayer.h"
30 #include "GEOM_AISShape.hxx"
32 #include "GEOM_Actor.h"
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>
40 #include <OCCViewer_ViewWindow.h>
41 #include <OCCViewer_ViewPort3d.h>
42 #include <OCCViewer_ViewModel.h>
43 #include <OCCViewer_ViewManager.h>
45 #include <SOCC_ViewModel.h>
46 #include <SOCC_ViewWindow.h>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_RenderWindowInteractor.h>
50 #include <SVTK_InteractorStyle.h>
51 #include <SVTK_ViewModel.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_Study.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <LightApp_VTKSelector.h>
58 #include <LightApp_DataObject.h>
59 #include <LightApp_Preferences.h>
61 #include <SALOME_LifeCycleCORBA.hxx>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
65 #include <SALOMEDSClient_ClientFactory.hxx>
66 #include <SALOMEDSClient_IParameters.hxx>
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 #include <Graphic3d_HArray1OfBytes.hxx>
85 #include <utilities.h>
87 #include <vtkCamera.h>
88 #include <vtkRenderer.h>
90 #include "GEOMImpl_Types.hxx"
95 Standard_EXPORT CAM_Module* createModule() {
96 return new GeometryGUI();
100 GeometryGUI::StudyTextureMap GeometryGUI::myTextureMap;
102 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
104 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
106 // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
107 if (CORBA::is_nil(myComponentGeom))
109 return GeometryGUI::myComponentGeom;
112 bool GeometryGUI::InitGeomGen()
115 if( CORBA::is_nil( myComponentGeom ) ) return false;
119 //=======================================================================
120 // function : ClientSObjectToObject
122 //=======================================================================
123 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
125 _PTR(GenericAttribute) anAttr;
126 CORBA::Object_var anObj;
128 std::string aValue = theSObject->GetIOR();
129 if (strcmp(aValue.c_str(), "") != 0) {
130 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
131 anObj = anORB->string_to_object(aValue.c_str());
134 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
136 return anObj._retn();
139 //=======================================================================
140 // function : ClientStudyToStudy
142 //=======================================================================
143 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
145 SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
146 CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
147 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
148 int aStudyID = theStudy->StudyId();
149 SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
150 return aDSStudy._retn();
153 //=======================================================================
154 // function : GeometryGUI::GeometryGUI()
155 // purpose : Constructor
156 //=======================================================================
157 GeometryGUI::GeometryGUI() :
158 SalomeApp_Module( "GEOM" ),
159 LightApp_Module( "GEOM" )
161 if ( CORBA::is_nil( myComponentGeom ) )
163 Engines::Component_var comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "GEOM" );
164 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
168 myActiveDialogBox = 0;
171 gp_Pnt origin = gp_Pnt(0., 0., 0.);
172 gp_Dir direction = gp_Dir(0., 0., 1.);
173 myWorkingPlane = gp_Ax3(origin, direction);
176 myLocalSelectionMode = GEOM_ALLOBJECTS;
179 //=======================================================================
180 // function : GeometryGUI::~GeometryGUI()
181 // purpose : Destructor
182 //=======================================================================
183 GeometryGUI::~GeometryGUI()
185 while (!myOCCSelectors.isEmpty())
186 delete myOCCSelectors.takeFirst();
188 while (!myVTKSelectors.isEmpty())
189 delete myVTKSelectors.takeFirst();
191 qDeleteAll(myGUIMap);
194 //=======================================================================
195 // function : GeometryGUI::getLibrary()
196 // purpose : get or load GUI library by name [ internal ]
197 //=======================================================================
198 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
199 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
201 if ( !myGUIMap.contains( libraryName ) ) {
202 // try to load library if it is not loaded yet
205 libs = getenv( "LD_LIBRARY_PATH" );
206 if( !libs.isEmpty() ) {
207 QStringList dirList = libs.split( ":", QString::SkipEmptyParts ); // skip empty entries
209 libs = getenv( "PATH" );
210 if( !libs.isEmpty() ) {
211 QStringList dirList = libs.split( ";", QString::SkipEmptyParts ); // skip empty entries
213 for( int i = dirList.count()-1; i >= 0; i-- ) {
214 QString dir = dirList[ i ];
215 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
217 OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().data() );
218 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
220 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
221 continue; // continue search further
223 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
224 if ( osdF != NULL ) {
225 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
226 GEOMGUI* libGUI = (*func)(this);
228 myGUIMap[ libraryName ] = libGUI;
229 break; // found and loaded!
236 if ( myGUIMap.contains( libraryName ) )
237 // library is successfully loaded
238 return myGUIMap[ libraryName ];
242 //=======================================================================
243 // function : GeometryGUI::ActiveWorkingPlane()
244 // purpose : Activate Working Plane View
245 //=======================================================================
246 void GeometryGUI::ActiveWorkingPlane()
248 gp_Dir DZ = myWorkingPlane.Direction();
249 gp_Dir DY = myWorkingPlane.YDirection();
251 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
252 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
253 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
256 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
258 Handle(V3d_View) view3d = vw->getViewPort()->getView();
260 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
261 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
267 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
269 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
271 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
272 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
273 camera->SetFocalPoint(0,0,0);
280 //=======================================================================
281 // function : GeometryGUI::SetActiveDialogBox()
282 // purpose : Set active dialog box
283 //=======================================================================
284 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
286 myActiveDialogBox = (QDialog*)aDlg;
289 //=======================================================================
290 // function : GeometryGUI::EmitSignalDeactivateDialog()
291 // purpose : Emit a signal to deactivate the active dialog Box
292 //=======================================================================
293 void GeometryGUI::EmitSignalDeactivateDialog()
295 emit SignalDeactivateActiveDialog();
298 //=======================================================================
299 // function : GeometryGUI::EmitSignalCloseAllDialogs()
300 // purpose : Emit a signal to close all non modal dialogs box
301 //=======================================================================
302 void GeometryGUI::EmitSignalCloseAllDialogs()
304 emit SignalCloseAllDialogs();
307 //=======================================================================
308 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
309 // purpose : Emit a signal to inform that default real spin box step has
311 //=======================================================================
312 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
314 emit SignalDefaultStepValueChanged(newVal);
317 //=======================================================================
318 // function : GeometryGUI::OnGUIEvent()
319 // purpose : common slot for all menu/toolbar actions
320 //=======================================================================
321 void GeometryGUI::OnGUIEvent()
323 const QObject* obj = sender();
324 if ( !obj || !obj->inherits( "QAction" ) )
326 int id = actionId((QAction*)obj);
331 //=======================================================================
332 // function : GeometryGUI::OnGUIEvent()
333 // purpose : manage all events on GUI [static]
334 //=======================================================================
335 void GeometryGUI::OnGUIEvent( int id )
337 SUIT_Application* anApp = application();
339 SUIT_Desktop* desk = anApp->desktop();
341 // check type of the active viewframe
342 SUIT_ViewWindow* window = desk->activeWindow();
343 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
344 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
345 // if current viewframe is not of OCC and not of VTK type - return immediately
346 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
347 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 || id == 33 || id == 8037 || id == 8038 || id == 8039 );
348 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
351 // fix for IPAL9103, point 2
352 if ( CORBA::is_nil( GetGeomGen() ) ) {
353 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
357 GEOMGUI* library = 0;
358 // try to get-or-load corresponding GUI library
359 if( id == 111 || // MENU FILE - IMPORT BREP
360 id == 112 || // MENU FILE - IMPORT IGES
361 id == 113 || // MENU FILE - IMPORT STEP
362 id == 121 || // MENU FILE - EXPORT BREP
363 id == 122 || // MENU FILE - EXPORT IGES
364 id == 123 || // MENU FILE - EXPORT STEP
365 id == 2171 || // POPUP VIEWER - SELECT ONLY - VERTEX
366 id == 2172 || // POPUP VIEWER - SELECT ONLY - EDGE
367 id == 2173 || // POPUP VIEWER - SELECT ONLY - WIRE
368 id == 2174 || // POPUP VIEWER - SELECT ONLY - FACE
369 id == 2175 || // POPUP VIEWER - SELECT ONLY - SHELL
370 id == 2176 || // POPUP VIEWER - SELECT ONLY - SOLID
371 id == 2177 || // POPUP VIEWER - SELECT ONLY - COMPOUND
372 id == 2178 || // POPUP VIEWER - SELECT ONLY - SELECT ALL
373 id == 31 || // MENU EDIT - COPY
374 id == 33 || // MENU EDIT - DELETE
375 id == 411 || // MENU SETTINGS - ADD IN STUDY
376 id == 412 || // MENU SETTINGS - SHADING COLOR
377 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
378 id == 8032 || // POPUP VIEWER - COLOR
379 id == 8033 || // POPUP VIEWER - TRANSPARENCY
380 id == 8034 || // POPUP VIEWER - ISOS
381 id == 8035 || // POPUP VIEWER - AUTO COLOR
382 id == 8036 || // POPUP VIEWER - DISABLE AUTO COLOR
383 id == 8037 || // POPUP VIEWER - SHOW CHILDREN
384 id == 8038 || // POPUP VIEWER - HIDE CHILDREN
385 id == 8039 || // POPUP VIEWER - POINT MARKER
386 id == 804 || // POPUP VIEWER - ADD IN STUDY
387 id == 901 || // OBJECT BROWSER - RENAME
388 id == 9024 ) { // OBJECT BROWSER - OPEN
389 //cout << "id " << id << " received" << endl;
391 library = getLibrary( "libGEOMToolsGUI.so" );
393 library = getLibrary( "GEOMToolsGUI.dll" );
396 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
397 id == 212 || // MENU VIEW - DISPLAY ALL
398 id == 213 || // MENU VIEW - DISPLAY ONLY
399 id == 214 || // MENU VIEW - ERASE ALL
400 id == 215 || // MENU VIEW - ERASE
401 id == 216 || // MENU VIEW - DISPLAY
402 id == 218 || // MENU VIEW - VECTOR MODE
403 id == 80311 || // POPUP VIEWER - WIREFRAME
404 id == 80312 || // POPUP VIEWER - SHADING
405 id == 80313 ) { // POPUP VIEWER - VECTORS
407 library = getLibrary( "libDisplayGUI.so" );
409 library = getLibrary( "DisplayGUI.dll" );
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 // DEPRECATED
420 id == 4019 || // MENU BASIC - CURVE
421 id == 4020 ) { // MENU BASIC - REPAIR
423 library = getLibrary( "libBasicGUI.so" );
425 library = getLibrary( "BasicGUI.dll" );
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
436 library = getLibrary( "libPrimitiveGUI.so" );
438 library = getLibrary( "PrimitiveGUI.dll" );
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
446 library = getLibrary( "libGenerationGUI.so" );
448 library = getLibrary( "GenerationGUI.dll" );
451 else if( id == 404 || // MENU ENTITY - SKETCHER
452 id == 405 || // MENU ENTITY - 3D SKETCHER
453 id == 407 ) { // MENU ENTITY - EXPLODE
455 library = getLibrary( "libEntityGUI.so" );
457 library = getLibrary( "EntityGUI.dll" );
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
467 library = getLibrary( "libBuildGUI.so" );
469 library = getLibrary( "BuildGUI.dll" );
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
477 library = getLibrary( "libBooleanGUI.so" );
479 library = getLibrary( "BooleanGUI.dll" );
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
492 library = getLibrary( "libTransformationGUI.so" );
494 library = getLibrary( "TransformationGUI.dll" );
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 id == 510 ) { // MENU OPERATION - FILLET 1D
506 library = getLibrary( "libOperationGUI.so" );
508 library = getLibrary( "OperationGUI.dll" );
511 else if( id == 601 || // MENU REPAIR - SEWING
512 id == 603 || // MENU REPAIR - SUPPRESS FACES
513 id == 604 || // MENU REPAIR - SUPPRESS HOLE
514 id == 605 || // MENU REPAIR - SHAPE PROCESSING
515 id == 606 || // MENU REPAIR - CLOSE CONTOUR
516 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
517 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
518 id == 609 || // MENU MEASURE - FREE BOUNDARIES
519 id == 610 || // MENU MEASURE - FREE FACES
520 id == 611 || // MENU REPAIR - CHANGE ORIENTATION
521 id == 602 || // MENU REPAIR - GLUE FACES
522 id == 612 ) { // MENU REPAIR - REMOVE EXTRA EDGES
524 library = getLibrary( "libRepairGUI.so" );
526 library = getLibrary( "RepairGUI.dll" );
529 else if( id == 701 || // MENU MEASURE - PROPERTIES
530 id == 702 || // MENU MEASURE - CDG
531 id == 703 || // MENU MEASURE - INERTIA
532 id == 704 || // MENU MEASURE - NORMALE
533 id == 7041 || // MENU MEASURE - BOUNDING BOX
534 id == 7042 || // MENU MEASURE - MIN DISTANCE
535 id == 7043 || // MENU MEASURE - ANGLE
536 id == 705 || // MENU MEASURE - TOLERANCE
537 id == 706 || // MENU MEASURE - WHATIS
538 id == 707 || // MENU MEASURE - CHECK
539 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
540 id == 708 ) { // MENU MEASURE - POINT COORDINATES
542 library = getLibrary( "libMeasureGUI.so" );
544 library = getLibrary( "MeasureGUI.dll" );
547 else if( id == 800 || // MENU GROUP - CREATE
548 id == 8001 || // POPUP MENU - CREATE GROUP
549 id == 801 ) { // MENU GROUP - EDIT
551 library = getLibrary( "libGroupGUI.so" );
553 library = getLibrary( "GroupGUI.dll" );
556 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
557 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
558 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
559 id == 99991 || // MENU BLOCKS - PROPAGATE
560 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
562 library = getLibrary( "libBlocksGUI.so" );
564 library = getLibrary( "BlocksGUI.dll" );
568 // call method of corresponding GUI library
570 library->OnGUIEvent( id, desk );
572 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
576 //=================================================================================
577 // function : GeometryGUI::OnKeyPress()
578 // purpose : Called when any key is pressed by user [static]
579 //=================================================================================
580 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
584 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
585 SUIT_Application* anApp = application();
587 bOk = bOk && it.value()->OnKeyPress( pe, anApp->desktop(), win );
593 //=================================================================================
594 // function : GeometryGUI::OnMouseMove()
595 // purpose : Manages mouse move events [static]
596 //=================================================================================
597 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
601 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
602 SUIT_Application* anApp = application();
604 bOk = bOk && it.value()->OnMouseMove( pe, anApp->desktop(), win );
610 //=================================================================================
611 // function : GeometryGUI::0nMousePress()
612 // purpose : Manage mouse press events [static]
613 //=================================================================================
614 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
617 // OnMousePress() should return false if this event should be processed further
618 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
619 bool processed = false;
620 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
621 SUIT_Application* anApp = application();
623 processed = processed || it.value()->OnMousePress( pe, anApp->desktop(), win );
629 static void UpdateVtkSelection()
631 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
632 SUIT_ViewWindow* win = 0;
633 for ( win = winList.first(); win; win = winList.next() ) {
634 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
635 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
637 SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
638 anInteractor->SetSelectionProp();
639 anInteractor->SetSelectionTolerance();
640 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
642 aStyle->setPreselectionProp();
649 //=================================================================================
650 // function : GeometryGUI::SetSettings()
651 // purpose : Called when GEOM module is activated [static]
652 //=================================================================================
653 bool GeometryGUI::SetSettings()
655 QMenuBar* Mb = parent->getMainMenuBar();
656 SUIT_Study* ActiveStudy = application()->activeStudy();
658 // Wireframe or Shading
660 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
661 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
662 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
664 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
666 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
667 DisplayMode = ic->DisplayMode();
670 else if ( ViewVTK ) {
671 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
673 SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
674 DisplayMode = myRenderInter->GetDisplayMode();
678 if( DisplayMode == 1 )
680 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
682 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
685 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
686 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
687 int Settings_AddInStudy;
688 // if(!AddInStudy.isEmpty())
689 // Settings_AddInStudy = AddInStudy.toInt();
692 Settings_AddInStudy = 1;
693 Mb->setItemChecked(411, Settings_AddInStudy);
696 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
698 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
701 int count = ActiveStudy->getStudyFramesCount();
702 for(int i = 0; i < count; i++) {
703 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
704 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
705 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
707 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
708 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
710 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
712 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
718 // PAL5356: update VTK selection
719 ::UpdateVtkSelection();
722 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
723 bOk = bOk && it.data()->SetSettings( parent );
725 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
726 if (getenv( "GEOM_CLIPPING" ) == NULL)
728 QMenuItem* mi = Mb->findItem(50);
729 if (mi && mi->popup())
730 mi->popup()->removeItem(507);
737 //=======================================================================
738 // function : createGeomAction
740 //=======================================================================
741 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
744 QWidget* parent = application()->desktop();
745 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
747 if ( icon_id.length() )
748 pix = resMgr->loadPixmap( "GEOM", tr( icon_id.toLatin1().constData() ) );
750 pix = resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+po_id).toLatin1().constData() ), false );
754 QString tooltip = tr( (QString( "TOP_" )+po_id).toLatin1().constData() ),
755 menu = tr( (QString( "MEN_" )+po_id).toLatin1().constData() ),
756 status_bar = tr( (QString( "STB_" )+po_id).toLatin1().constData() );
758 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
763 //=======================================================================
764 // function : GeometryGUI::initialize()
765 // purpose : Called when GEOM module is created
766 //=======================================================================
767 void GeometryGUI::initialize( CAM_Application* app )
769 SalomeApp_Module::initialize( app );
771 // ----- create actions --------------
773 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
774 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
776 createGeomAction( 33, "DELETE", "", Qt::Key_Delete );
778 createGeomAction( 4011, "POINT" );
779 createGeomAction( 4012, "LINE" );
780 createGeomAction( 4013, "CIRCLE" );
781 createGeomAction( 4014, "ELLIPSE" );
782 createGeomAction( 4015, "ARC" );
783 createGeomAction( 4019, "CURVE" );
784 createGeomAction( 4016, "VECTOR" );
785 createGeomAction( 4017, "PLANE" );
786 // createGeomAction( 4018, "WORK_PLANE" ); DEPRECATED
787 createGeomAction( 4020, "LOCAL_CS" );
789 createGeomAction( 4021, "BOX" );
790 createGeomAction( 4022, "CYLINDER" );
791 createGeomAction( 4023, "SPHERE" );
792 createGeomAction( 4024, "TORUS" );
793 createGeomAction( 4025, "CONE" );
794 createGeomAction( 4026, "FACE" );
795 createGeomAction( 4027, "DISK" );
797 createGeomAction( 4031, "EXTRUSION" );
798 createGeomAction( 4032, "REVOLUTION" );
799 createGeomAction( 4033, "FILLING" );
800 createGeomAction( 4034, "PIPE" );
802 createGeomAction( 800, "GROUP_CREATE" );
803 createGeomAction( 801, "GROUP_EDIT" );
805 createGeomAction( 5029, "RELOAD_IMPORTED" );
807 createGeomAction( 9997, "Q_FACE" );
808 createGeomAction( 9999, "HEX_SOLID" );
810 createGeomAction( 404, "SKETCH" );
811 createGeomAction( 405, "3DSKETCH" );
812 createGeomAction( 407, "EXPLODE" );
814 createGeomAction( 4081, "EDGE" );
815 createGeomAction( 4082, "WIRE" );
816 createGeomAction( 4083, "FACE" );
817 createGeomAction( 4084, "SHELL" );
818 createGeomAction( 4085, "SOLID" );
819 createGeomAction( 4086, "COMPOUND" );
821 createGeomAction( 5011, "FUSE" );
822 createGeomAction( 5012, "COMMON" );
823 createGeomAction( 5013, "CUT" );
824 createGeomAction( 5014, "SECTION" );
826 createGeomAction( 5021, "TRANSLATION" );
827 createGeomAction( 5022, "ROTATION" );
828 createGeomAction( 5023, "MODIFY_LOCATION" );
829 createGeomAction( 5024, "MIRROR" );
830 createGeomAction( 5025, "SCALE" );
831 createGeomAction( 5026, "OFFSET" );
832 createGeomAction( 5027, "MUL_TRANSLATION" );
833 createGeomAction( 5028, "MUL_ROTATION" );
835 createGeomAction( 503, "PARTITION" );
836 createGeomAction( 504, "ARCHIMEDE" );
837 createGeomAction( 505, "FILLET" );
838 createGeomAction( 506, "CHAMFER" );
839 //createGeomAction( 507, "CLIPPING" );
840 createGeomAction( 508, "GET_SHAPES_ON_SHAPES" );
841 createGeomAction( 510, "FILLET_1D" );
842 createGeomAction( 509, "FILLET_2D" );
844 createGeomAction( 9998, "MUL_TRANSFORM" );
845 createGeomAction( 9995, "EXPLODE_BLOCKS" );
846 createGeomAction( 99991, "PROPAGATE" );
848 createGeomAction( 601, "SEWING" );
849 createGeomAction( 602, "GLUE_FACES" );
850 createGeomAction( 603, "SUPPRESS_FACES" );
851 createGeomAction( 604, "SUPPERSS_HOLES" );
852 createGeomAction( 605, "SHAPE_PROCESS" );
853 createGeomAction( 606, "CLOSE_CONTOUR" );
854 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
855 createGeomAction( 608, "POINT_ON_EDGE" );
856 createGeomAction( 609, "CHECK_FREE_BNDS" );
857 createGeomAction( 610, "CHECK_FREE_FACES" );
858 createGeomAction( 611, "CHANGE_ORIENTATION" );
859 createGeomAction( 612, "REMOVE_EXTRA_EDGES" );
861 createGeomAction( 708, "POINT_COORDS" );
862 createGeomAction( 701, "BASIC_PROPS" );
863 createGeomAction( 702, "MASS_CENTER" );
864 createGeomAction( 703, "INERTIA" );
865 createGeomAction( 704, "NORMALE" );
866 createGeomAction( 7041, "BND_BOX" );
867 createGeomAction( 7042, "MIN_DIST" );
868 createGeomAction( 7043, "MEASURE_ANGLE" );
870 createGeomAction( 705, "TOLERANCE" );
871 createGeomAction( 706, "WHAT_IS" );
872 createGeomAction( 707, "CHECK" );
873 createGeomAction( 7072, "CHECK_COMPOUND" );
875 #ifdef _DEBUG_ // PAL16821
876 createGeomAction( 5103, "CHECK_GEOMETRY" );
878 createGeomAction( 412, "SHADING_COLOR" );
880 createGeomAction( 211, "SHADING" );
881 createGeomAction( 212, "DISPLAY_ALL" );
882 createGeomAction( 214, "ERASE_ALL" );
883 createGeomAction( 216, "DISPLAY" );
884 createGeomAction( 218, "VECTOR_MODE");
885 createGeomAction( 2171, "VERTEX_SEL_ONLY" ,"", 0, true );
886 createGeomAction( 2172, "EDGE_SEL_ONLY", "", 0, true );
887 createGeomAction( 2173, "WIRE_SEL_ONLY", "", 0, true );
888 createGeomAction( 2174, "FACE_SEL_ONLY", "", 0, true );
889 createGeomAction( 2175, "SHELL_SEL_ONLY", "", 0, true );
890 createGeomAction( 2176, "SOLID_SEL_ONLY", "", 0, true );
891 createGeomAction( 2177, "COMPOUND_SEL_ONLY", "", 0, true );
892 createGeomAction( 2178, "ALL_SEL_ONLY", "", 0, true );
893 createGeomAction( 213, "DISPLAY_ONLY" );
894 createGeomAction( 215, "ERASE" );
896 createGeomAction( 901, "POP_RENAME", "", Qt::Key_F2 );
897 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
898 createGeomAction( 80312, "POP_SHADING", "", 0, true );
899 createGeomAction( 80313, "POP_VECTORS", "", 0, true );
900 createGeomAction( 8032, "POP_COLOR" );
901 createGeomAction( 8033, "POP_TRANSPARENCY" );
902 createGeomAction( 8034, "POP_ISOS" );
903 createGeomAction( 8035, "POP_AUTO_COLOR" );
904 createGeomAction( 8036, "POP_DISABLE_AUTO_COLOR" );
905 createGeomAction( 8001, "POP_CREATE_GROUP" );
906 createGeomAction( 8037, "POP_SHOW_CHILDREN" );
907 createGeomAction( 8038, "POP_HIDE_CHILDREN" );
908 createGeomAction( 8039, "POP_POINT_MARKER" );
910 // make wireframe-shading items to be exclusive (only one at a time is selected)
911 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
912 //dispModeGr->add( action( 80311 ) );
913 //dispModeGr->add( action( 80312 ) );
914 // ---- create menu --------------------------
916 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
917 createMenu( separator(), fileId, 10 );
918 createMenu( 111, fileId, 10 );
919 createMenu( 121, fileId, 10 );
920 createMenu( separator(), fileId, -1 );
922 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
923 createMenu( 33, editId, -1 );
925 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
927 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
928 createMenu( 4011, basicId, -1 );
929 createMenu( 4012, basicId, -1 );
930 createMenu( 4013, basicId, -1 );
931 createMenu( 4014, basicId, -1 );
932 createMenu( 4015, basicId, -1 );
933 createMenu( 4019, basicId, -1 );
934 createMenu( separator(), basicId, -1 );
935 createMenu( 4016, basicId, -1 );
936 createMenu( 4017, basicId, -1 );
937 // createMenu( 4018, basicId, -1 ); DEPRECATED
938 createMenu( 4020, basicId, -1 );
940 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
941 createMenu( 4021, primId, -1 );
942 createMenu( 4022, primId, -1 );
943 createMenu( 4023, primId, -1 );
944 createMenu( 4024, primId, -1 );
945 createMenu( 4025, primId, -1 );
946 createMenu( 4026, primId, -1 );
947 createMenu( 4027, primId, -1 );
949 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
950 createMenu( 4031, genId, -1 );
951 createMenu( 4032, genId, -1 );
952 createMenu( 4033, genId, -1 );
953 createMenu( 4034, genId, -1 );
954 createMenu( separator(), newEntId, -1 );
956 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
957 createMenu( 800, groupId, -1 );
958 createMenu( 801, groupId, -1 );
959 createMenu( separator(), newEntId, -1 );
961 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
962 createMenu( 9997, blocksId, -1 );
963 createMenu( 9999, blocksId, -1 );
965 createMenu( separator(), newEntId, -1 );
966 createMenu( 404, newEntId, -1 );
967 createMenu( 405, newEntId, -1 );
968 createMenu( separator(), newEntId, -1 );
969 createMenu( 407, newEntId, -1 );
971 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
972 createMenu( 4081, buildId, -1 );
973 createMenu( 4082, buildId, -1 );
974 createMenu( 4083, buildId, -1 );
975 createMenu( 4084, buildId, -1 );
976 createMenu( 4085, buildId, -1 );
977 createMenu( 4086, buildId, -1 );
979 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
981 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
982 createMenu( 5011, boolId, -1 );
983 createMenu( 5012, boolId, -1 );
984 createMenu( 5013, boolId, -1 );
985 createMenu( 5014, boolId, -1 );
987 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
988 createMenu( 5021, transId, -1 );
989 createMenu( 5022, transId, -1 );
990 createMenu( 5023, transId, -1 );
991 createMenu( 5024, transId, -1 );
992 createMenu( 5025, transId, -1 );
993 createMenu( 5026, transId, -1 );
994 createMenu( separator(), transId, -1 );
995 createMenu( 5027, transId, -1 );
996 createMenu( 5028, transId, -1 );
998 createMenu( 503, operId, -1 );
999 createMenu( 504, operId, -1 );
1000 createMenu( 508, operId, -1 );
1001 createMenu( separator(), operId, -1 );
1002 createMenu( 510, transId, -1 );
1003 createMenu( 509, transId, -1 );
1004 createMenu( 505, transId, -1 );
1005 createMenu( 506, transId, -1 );
1006 //createMenu( 507, transId, -1 );
1008 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
1009 createMenu( 9998, blockId, -1 );
1010 createMenu( 9995, blockId, -1 );
1011 createMenu( 99991, blockId, -1 );
1013 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
1014 createMenu( 605, repairId, -1 );
1015 createMenu( 603, repairId, -1 );
1016 createMenu( 606, repairId, -1 );
1017 createMenu( 607, repairId, -1 );
1018 createMenu( 604, repairId, -1 );
1019 createMenu( 601, repairId, -1 );
1020 createMenu( 602, repairId, -1 );
1021 createMenu( 608, repairId, -1 );
1022 //createMenu( 609, repairId, -1 );
1023 //createMenu( 610, repairId, -1 );
1024 createMenu( 611, repairId, -1 );
1025 createMenu( 612, repairId, -1 );
1027 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
1028 createMenu( 708, measurId, -1 );
1029 createMenu( 701, measurId, -1 );
1030 createMenu( separator(), measurId, -1 );
1031 createMenu( 702, measurId, -1 );
1032 createMenu( 703, measurId, -1 );
1033 createMenu( 704, measurId, -1 );
1034 // NPAL16572: move "Check free boundaries" and "Check free faces" from "Repair" to "Measure"
1035 createMenu( separator(), measurId, -1 );
1036 createMenu( 609, measurId, -1 );
1037 createMenu( 610, measurId, -1 );
1039 createMenu( separator(), measurId, -1 );
1041 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
1042 createMenu( 7041, dimId, -1 );
1043 createMenu( 7042, dimId, -1 );
1044 createMenu( 7043, dimId, -1 );
1045 createMenu( separator(), measurId, -1 );
1047 createMenu( 705, measurId, -1 );
1048 createMenu( separator(), measurId, -1 );
1049 createMenu( 706, measurId, -1 );
1050 createMenu( 707, measurId, -1 );
1051 createMenu( 7072, measurId, -1 );
1053 #ifdef _DEBUG_ // PAL16821
1054 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1055 createMenu( separator(), toolsId, -1 );
1056 createMenu( 5103, toolsId, -1 );
1058 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
1059 //createMenu( separator(), prefId, -1 );
1060 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
1061 //createMenu( 412, geomId, -1 );
1062 //createMenu( separator(), prefId, -1 );
1064 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1065 createMenu( separator(), viewId, -1 );
1067 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1068 createMenu( 211, dispmodeId, -1 );
1069 createMenu( separator(), dispmodeId, -1 );
1070 createMenu( 218, dispmodeId, -1 );
1072 createMenu( separator(), viewId, -1 );
1073 createMenu( 212, viewId, -1 );
1074 createMenu( 214, viewId, -1 );
1075 createMenu( separator(), viewId, -1 );
1079 because of these items are accessible through object browser and viewers
1080 we have removed they from main menu
1082 createMenu( 216, viewId, -1 );
1083 createMenu( 213, viewId, -1 );
1084 createMenu( 215, viewId, -1 );
1087 // ---- create toolbars --------------------------
1089 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1090 createTool( 4011, basicTbId );
1091 createTool( 4012, basicTbId );
1092 createTool( 4013, basicTbId );
1093 createTool( 4014, basicTbId );
1094 createTool( 4015, basicTbId );
1095 createTool( 4019, basicTbId );
1096 createTool( 4016, basicTbId );
1097 createTool( 4017, basicTbId );
1098 // createTool( 4018, basicTbId ); DEPRECATED
1099 createTool( 4020, basicTbId );
1101 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1102 createTool( 4021, primTbId );
1103 createTool( 4022, primTbId );
1104 createTool( 4023, primTbId );
1105 createTool( 4024, primTbId );
1106 createTool( 4025, primTbId );
1107 createTool( 4026, primTbId );
1108 createTool( 4027, primTbId );
1110 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1111 createTool( 5011, boolTbId );
1112 createTool( 5012, boolTbId );
1113 createTool( 5013, boolTbId );
1114 createTool( 5014, boolTbId );
1116 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1117 createTool( 4031, genTbId );
1118 createTool( 4032, genTbId );
1119 createTool( 4033, genTbId );
1120 createTool( 4034, genTbId );
1122 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1123 createTool( 5021, transTbId );
1124 createTool( 5022, transTbId );
1125 createTool( 5023, transTbId );
1126 createTool( 5024, transTbId );
1127 createTool( 5025, transTbId );
1128 createTool( 5026, transTbId );
1129 createTool( separator(), transTbId );
1130 createTool( 5027, transTbId );
1131 createTool( 5028, transTbId );
1133 // ---- create popup menus --------------------------
1135 QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1136 QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1138 QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1139 QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1141 QString autoColorPrefix =
1142 "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1144 QtxPopupMgr* mgr = popupMgr();
1145 mgr->insert( action( 901 ), -1, -1 ); // rename
1146 mgr->setRule( action( 901 ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1147 mgr->insert( action( 33 ), -1, -1 ); // delete
1148 mgr->setRule( action( 33 ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1149 mgr->insert( action( 8001 ), -1, -1 ); // create group
1150 mgr->setRule( action( 8001 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1151 mgr->insert( action( 8037 ), -1, -1 ); // show children
1152 mgr->setRule( action( 8037 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasHiddenChildren=true"), QtxPopupMgr::VisibleRule );
1153 mgr->insert( action( 8038 ), -1, -1 ); // hide children
1154 mgr->setRule( action( 8038 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and hasShownChildren=true"), QtxPopupMgr::VisibleRule );
1155 mgr->insert( action( 801 ), -1, -1 ); // edit group
1156 mgr->setRule( action( 801 ), QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1157 mgr->insert( separator(), -1, -1 ); // -----------
1158 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1159 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1160 mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1161 mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1162 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1163 mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1164 mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1165 mgr->insert( separator(), dispmodeId, -1 );
1166 mgr->insert( action( 80313 ), dispmodeId, -1 ); // vectors
1167 mgr->setRule( action( 80313 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1168 mgr->setRule( action( 80313 ), clientOCCorVTK + " and isVectorsMode", QtxPopupMgr::ToggleRule );
1169 mgr->insert( separator(), -1, -1 ); // -----------
1170 mgr->insert( action( 8032 ), -1, -1 ); // color
1171 mgr->setRule( action( 8032 ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1172 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1173 mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1174 mgr->insert( action( 8034 ), -1, -1 ); // isos
1175 mgr->setRule( action( 8034 ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1176 mgr->insert( action( 8039 ), -1, -1 ); // point marker
1177 mgr->setRule( action( 8039 ), QString( "selcount>0 and $typeid in {%1}" ).arg( GEOM_POINT ), QtxPopupMgr::VisibleRule );
1178 mgr->insert( separator(), -1, -1 ); // -----------
1179 mgr->insert( action( 8035 ), -1, -1 ); // auto color
1180 mgr->setRule( action( 8035 ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1181 mgr->insert( action( 8036 ), -1, -1 ); // disable auto color
1182 mgr->setRule( action( 8036 ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1183 mgr->insert( separator(), -1, -1 ); // -----------
1186 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1187 onlyComponent = "((type='Component') and selcount=1)",
1188 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1189 types = "'Shape' 'Group'";
1191 mgr->insert( action( 216 ), -1, -1 ); // display
1192 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1194 mgr->insert( action( 215 ), -1, -1 ); // erase
1195 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1197 mgr->insert( action( 214 ), -1, -1 ); // erase All
1198 mgr->setRule( action( 214 ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1200 QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1202 int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1); //select only menu
1203 mgr->insert( action(2171), selectolnyId, -1); //Vertex
1204 mgr->setRule(action(2171), selectOnly, QtxPopupMgr::VisibleRule);
1205 mgr->setRule(action(2171), selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1206 mgr->insert( action(2172), selectolnyId, -1); //Edge
1207 mgr->setRule(action(2172), selectOnly, QtxPopupMgr::VisibleRule);
1208 mgr->setRule(action(2172), selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1209 mgr->insert( action(2173), selectolnyId, -1); //Wire
1210 mgr->setRule(action(2173), selectOnly, QtxPopupMgr::VisibleRule);
1211 mgr->setRule(action(2173), selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1212 mgr->insert( action(2174), selectolnyId, -1); //Face
1213 mgr->setRule(action(2174), selectOnly, QtxPopupMgr::VisibleRule);
1214 mgr->setRule(action(2174), selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1215 mgr->insert( action(2175), selectolnyId, -1); //Shell
1216 mgr->setRule(action(2175), selectOnly, QtxPopupMgr::VisibleRule);
1217 mgr->setRule(action(2175), selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1218 mgr->insert( action(2176), selectolnyId, -1); //Solid
1219 mgr->setRule(action(2176), selectOnly, QtxPopupMgr::VisibleRule);
1220 mgr->setRule(action(2176), selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1221 mgr->insert( action(2177), selectolnyId, -1); //Compound
1222 mgr->setRule(action(2177), selectOnly, QtxPopupMgr::VisibleRule);
1223 mgr->setRule(action(2177), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1224 mgr->insert( separator(), selectolnyId, -1);
1225 mgr->insert( action(2178), selectolnyId, -1); //Clear selection filter
1226 mgr->setRule(action(2178), selectOnly, QtxPopupMgr::VisibleRule);
1227 mgr->setRule(action(2178), selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1228 mgr->insert( action( 213 ), -1, -1 ); // display only
1229 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1230 mgr->insert( separator(), -1, -1 );
1232 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1235 //=======================================================================
1236 // function : GeometryGUI::activateModule()
1237 // purpose : Called when GEOM module is activated
1238 //=======================================================================
1239 bool GeometryGUI::activateModule( SUIT_Study* study )
1241 if ( CORBA::is_nil( myComponentGeom ) )
1244 bool res = SalomeApp_Module::activateModule( study );
1249 setMenuShown( true );
1250 setToolShown( true );
1252 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1253 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1255 // Reset actions accelerator keys
1256 //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1257 //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1258 action(111)->setEnabled( true ); // Import: CTRL + Key_I
1259 action(121)->setEnabled( true ); // Export: CTRL + Key_E
1260 action( 33)->setEnabled( true ); // Delete: Key_Delete
1261 action(901)->setEnabled( true ); // Rename: Key_F2
1263 GUIMap::Iterator it;
1264 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1265 it.value()->activate( application()->desktop() );
1267 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1269 SUIT_ViewManager* vm;
1270 ViewManagerList OCCViewManagers, VTKViewManagers;
1272 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1273 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1274 while ( itOCC.hasNext() && (vm = itOCC.next()) )
1275 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1277 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1278 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1279 while ( itVTK.hasNext() && (vm = itVTK.next()) )
1280 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1283 SALOME_ListIO selected;
1284 sm->selectedObjects( selected );
1285 sm->clearSelected();
1287 // disable OCC selectors
1288 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1289 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1290 while ( itOCCSel.hasNext() )
1291 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1292 sr->setEnabled(true);
1294 // disable VTK selectors
1295 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1296 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1297 while ( itVTKSel.hasNext() )
1298 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1299 sr->setEnabled(true);
1301 sm->setSelectedObjects( selected, true ); //NPAL 19674
1303 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1305 connect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1311 //=======================================================================
1312 // function : GeometryGUI::deactivateModule()
1313 // purpose : Called when GEOM module is deactivated
1314 //=======================================================================
1315 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1317 QMenu* viewMenu = menuMgr()->findMenu( STD_Application::MenuViewId );
1319 disconnect( viewMenu, SIGNAL( aboutToShow() ), this, SLOT( onViewAboutToShow() ) );
1321 setMenuShown( false );
1322 setToolShown( false );
1324 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1325 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1327 EmitSignalCloseAllDialogs();
1329 GUIMap::Iterator it;
1330 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1331 it.value()->deactivate();
1333 // Unset actions accelerator keys
1334 //action(111)->setAccel(QKeySequence()); // Import
1335 //action(121)->setAccel(QKeySequence()); // Export
1336 action(111)->setEnabled( false ); // Import: CTRL + Key_I
1337 action(121)->setEnabled( false ); // Export: CTRL + Key_E
1338 action( 33)->setEnabled( false ); // Delete: Key_Delete
1339 action(901)->setEnabled( false ); // Rename: Key_F2
1341 qDeleteAll(myOCCSelectors);
1342 myOCCSelectors.clear();
1343 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1345 qDeleteAll(myVTKSelectors);
1346 myVTKSelectors.clear();
1347 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1349 return SalomeApp_Module::deactivateModule( study );
1352 //=======================================================================
1353 // function : GeometryGUI::BuildPresentation()
1355 //=======================================================================
1356 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1358 //GEOM_Displayer().Display( io, false, win );
1361 //=======================================================================
1362 // function : onWindowActivated()
1363 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1364 //=======================================================================
1365 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1370 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1371 //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1373 // disable non-OCC viewframe menu commands
1374 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1375 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1376 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1377 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1378 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1379 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1380 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1382 action( 800 )->setEnabled( ViewOCC ); // Create Group
1383 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1385 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1388 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1390 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1391 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1394 void GeometryGUI::viewManagers( QStringList& lst ) const
1396 lst.append( OCCViewer_Viewer::Type() );
1399 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1401 if ( vm->getType() == OCCViewer_Viewer::Type() )
1403 qDebug( "connect" );
1404 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1405 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1406 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1407 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1408 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1409 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1412 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1413 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1415 // disable OCC selectors
1416 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1417 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1418 while ( itOCCSel.hasNext() )
1419 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1420 sr->setEnabled(true);
1422 else if ( vm->getType() == SVTK_Viewer::Type() )
1424 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1425 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1427 // disable VTK selectors
1428 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1429 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1430 while ( itVTKSel.hasNext() )
1431 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1432 sr->setEnabled(true);
1436 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1438 SUIT_ViewModel* viewer = vm->getViewModel();
1439 if ( vm->getType() == OCCViewer_Viewer::Type() )
1441 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1442 while ( itOCCSel.hasNext() )
1443 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1444 if ( sr->viewer() == viewer )
1446 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1450 if ( vm->getType() == SVTK_Viewer::Type() )
1452 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1453 while ( itVTKSel.hasNext() )
1454 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1455 if ( sr->viewer() == viewer )
1457 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1463 QString GeometryGUI::engineIOR() const
1465 if ( !CORBA::is_nil( GetGeomGen() ) )
1466 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1470 Handle(Graphic3d_HArray1OfBytes) GeometryGUI::getTexture( SalomeApp_Study* theStudy, int theId, int& theWidth, int& theHeight )
1472 theWidth = theHeight = 0;
1473 Handle(Graphic3d_HArray1OfBytes) aTexture;
1475 TextureMap aTextureMap = myTextureMap[ theStudy->studyDS()->StudyId() ];
1476 aTexture = aTextureMap[ theId ];
1477 if ( aTexture.IsNull() ) {
1478 GEOM::GEOM_IInsertOperations_var aInsOp = GeometryGUI::GetGeomGen()->GetIInsertOperations( theStudy->studyDS()->StudyId() );
1479 if ( !aInsOp->_is_nil() ) {
1480 CORBA::Long aWidth, aHeight;
1481 SALOMEDS::TMPFile_var aStream = aInsOp->GetTexture( theId, aWidth, aHeight );
1482 if ( aWidth > 0 && aHeight > 0 && aStream->length() > 0 ) {
1484 theHeight = aHeight;
1485 aTexture = new Graphic3d_HArray1OfBytes( 1, aStream->length() );
1486 for ( int i = 0; i < aStream->length(); i++ )
1487 aTexture->SetValue( i+1, (Standard_Byte)aStream[i] );
1488 aTextureMap[ theId ] = aTexture;
1496 LightApp_Selection* GeometryGUI::createSelection() const
1498 return new GEOMGUI_Selection();
1501 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1503 SalomeApp_Module::contextMenuPopup(client, menu, title);
1506 getApp()->selectionMgr()->selectedObjects(lst);
1507 if (lst.Extent() < 1)
1510 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1511 _PTR(Study) study = appStudy->studyDS();
1513 bool isImported = true;
1514 SALOME_ListIteratorOfListIO anIt (lst);
1515 for (; anIt.More() && isImported; anIt.Next()) {
1516 Handle(SALOME_InteractiveObject) io = anIt.Value();
1517 _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1519 if (lst.Extent() == 1) {
1520 // Set context menu title
1521 if (client == "OCCViewer" || client == "VTKViewer")
1522 title = QString(aSObj->GetName().c_str());
1525 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1526 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1527 if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1533 menu->addAction(action(5029)); // Reload imported shape
1537 void GeometryGUI::createPreferences()
1539 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1541 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1542 setPreferenceProperty( genGroup, "columns", 2 );
1544 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1545 LightApp_Preferences::Selector,
1546 "Geometry", "display_mode" );
1548 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1549 LightApp_Preferences::Color, "Geometry", "shading_color" );
1551 addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1552 LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1554 addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1555 LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1557 addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1558 LightApp_Preferences::Color, "Geometry", "line_color" );
1560 addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1561 LightApp_Preferences::Color, "Geometry", "point_color" );
1563 addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1564 LightApp_Preferences::Color, "Geometry", "isos_color" );
1566 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1567 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1569 int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1570 setPreferenceProperty( VertexGroup, "columns", 2 );
1572 int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1573 LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1575 int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1576 LightApp_Preferences::Selector, "Geometry", "marker_scale" );
1578 // Set property for default display mode
1579 QStringList aModesList;
1580 aModesList.append( tr("MEN_WIREFRAME") );
1581 aModesList.append( tr("MEN_SHADING") );
1583 QList<QVariant> anIndexesList;
1584 anIndexesList.append(0);
1585 anIndexesList.append(1);
1587 setPreferenceProperty( dispmode, "strings", aModesList );
1588 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1590 // Set property for step value for spinboxes
1591 setPreferenceProperty( step, "min", 1 );
1592 setPreferenceProperty( step, "max", 10000 );
1593 setPreferenceProperty( step, "precision", 3 );
1595 // Set property vertex marker type
1596 QList<QVariant> aMarkerTypeIndicesList;
1597 QList<QVariant> aMarkerTypeIconsList;
1599 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1600 for ( int i = GEOM::MT_POINT; i < GEOM::MT_USER; i++ ) {
1601 QString icoFile = QString( "ICON_VERTEX_MARKER_%1" ).arg( i );
1602 QPixmap pixmap = resMgr->loadPixmap( "GEOM", tr( qPrintable( icoFile ) ) );
1603 aMarkerTypeIndicesList << (i-1);
1604 aMarkerTypeIconsList << pixmap;
1607 setPreferenceProperty( typeOfMarker, "indexes", aMarkerTypeIndicesList );
1608 setPreferenceProperty( typeOfMarker, "icons", aMarkerTypeIconsList );
1610 // Set property for vertex marker scale
1611 QList<QVariant> aMarkerScaleIndicesList;
1612 QStringList aMarkerScaleValuesList;
1614 for ( int i = GEOM::MS_10; i <= GEOM::MS_70; i++ ) {
1615 aMarkerScaleIndicesList << i;
1616 aMarkerScaleValuesList << QString::number( (i-(int)GEOM::MS_10)*0.5 + 1.0 );
1619 setPreferenceProperty( markerScale, "strings", aMarkerScaleValuesList );
1620 setPreferenceProperty( markerScale, "indexes", aMarkerScaleIndicesList );
1623 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1625 if (section == "Geometry") {
1626 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1627 if (param == QString("SettingsGeomStep")) {
1628 double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1629 EmitSignalDefaultStepValueChanged(spin_step);
1634 LightApp_Displayer* GeometryGUI::displayer()
1637 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1641 void GeometryGUI::setLocalSelectionMode(const int mode)
1643 myLocalSelectionMode = mode;
1645 int GeometryGUI::getLocalSelectionMode() const
1647 return myLocalSelectionMode;
1650 const char gSeparator = '_'; // character used to separate parameter names
1651 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1654 * \brief Store visual parameters
1656 * This method is called just before the study document is saved.
1657 * Store visual parameters in AttributeParameter attribue(s)
1659 void GeometryGUI::storeVisualParameters (int savePoint)
1661 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1662 if (!appStudy || !appStudy->studyDS())
1664 _PTR(Study) studyDS = appStudy->studyDS();
1666 // componentName is used for encoding of entries when storing them in IParameters
1667 std::string componentName = myComponentGeom->ComponentDataType();
1668 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1669 //if (!aSComponent) return;
1672 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1673 componentName.c_str(),
1675 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1677 // viewers counters are used for storing view_numbers in IParameters
1678 int vtkViewers(0), occViewers(0);
1680 QList<SUIT_ViewManager*> lst;
1681 QList<SUIT_ViewManager*>::Iterator it;
1683 // main cycle to store parameters of displayed objects
1685 vtkViewers = occViewers = 0;
1686 getApp()->viewManagers(lst);
1687 for (it = lst.begin(); it != lst.end(); it++)
1689 SUIT_ViewManager* vman = *it;
1690 QString vType = vman->getType();
1692 // saving VTK actors properties
1693 if (vType == SVTK_Viewer::Type())
1695 QVector<SUIT_ViewWindow*> views = vman->getViews();
1696 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1698 if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1700 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1701 allActors->InitTraversal();
1702 while (vtkActor* actor = allActors->GetNextActor())
1704 if (actor->GetVisibility()) // store only visible actors
1706 GEOM_Actor* aGeomActor = 0;
1707 if (actor->IsA("GEOM_Actor"))
1708 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1709 if (aGeomActor && aGeomActor->hasIO())
1711 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1714 // entry is "encoded" = it does NOT contain component adress, since it is a
1715 // subject to change on next component loading
1716 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1718 std::string param, occParam = vType.toLatin1().data();
1719 occParam += gSeparator;
1720 occParam += QString::number(vtkViewers).toLatin1().data();
1721 occParam += gSeparator;
1723 param = occParam + "Visibility";
1724 ip->setParameter(entry, param, "On");
1726 param = occParam + "DisplayMode";
1727 ip->setParameter(entry, param, QString::number
1728 (aGeomActor->getDisplayMode()).toLatin1().data());
1730 vtkFloatingPointType r, g, b;
1731 aGeomActor->GetColor(r, g, b);
1732 QString colorStr = QString::number(r);
1733 colorStr += gDigitsSep; colorStr += QString::number(g);
1734 colorStr += gDigitsSep; colorStr += QString::number(b);
1735 param = occParam + "Color";
1736 ip->setParameter(entry, param, colorStr.toLatin1().data());
1738 param = occParam + "Opacity";
1739 ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1741 int nbUIso(0), nbVIso(0);
1742 aGeomActor->GetNbIsos(nbUIso,nbVIso);
1743 QString isosStr = QString::number(nbUIso);
1744 isosStr += gDigitsSep;
1745 isosStr += QString::number(nbVIso);
1746 param = occParam + "Isos";
1747 ip->setParameter(entry, param, isosStr.toLatin1().data());
1748 } // if (io->hasEntry())
1749 } // GEOM_Actor && hasIO
1751 } // while.. actors traversal
1755 } // if (SVTK view model)
1756 else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1758 QVector<SUIT_ViewWindow*> views = vman->getViews();
1759 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1761 SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1764 //Handle(AIS_InteractiveContext) ic =
1765 // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1766 OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1767 //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1768 Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1770 AIS_ListOfInteractive aList;
1771 ic->DisplayedObjects(aList);
1773 AIS_ListIteratorOfListOfInteractive ite (aList);
1774 for (; ite.More(); ite.Next())
1776 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1778 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1781 Handle(SALOME_InteractiveObject) io =
1782 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1785 // entry is "encoded": it does NOT contain component adress,
1786 // since it is a subject to change on next component loading
1787 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1789 std::string param, occParam = vType.toLatin1().data();
1790 occParam += gSeparator;
1791 occParam += QString::number(occViewers).toLatin1().data();
1792 occParam += gSeparator;
1795 param = occParam + "Visibility";
1796 ip->setParameter(entry, param, "On");
1799 param = occParam + "DisplayMode";
1800 int dm = aSh->DisplayMode();
1801 ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1804 // is a property of GEOM_Object, it is stored by GEOM engine
1807 param = occParam + "Transparency";
1808 ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1811 Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1812 int nbUIso = aDrawer->UIsoAspect()->Number();
1813 int nbVIso = aDrawer->VIsoAspect()->Number();
1814 QString isosStr = QString::number(nbUIso);
1815 isosStr += gDigitsSep;
1816 isosStr += QString::number(nbVIso);
1817 param = occParam + "Isos";
1818 ip->setParameter(entry, param, isosStr.toLatin1().data());
1819 } // if (io->hasEntry())
1821 } // if (GEOM_AISShape)
1822 } // for (AIS_ListOfInteractive)
1826 } // if (SOCC view model)
1829 // unknown viewer type
1831 } // for (viewManagers)
1835 * \brief Restore visual parameters
1837 * This method is called after the study document is opened.
1838 * Restore visual parameters from AttributeParameter attribue(s)
1840 void GeometryGUI::restoreVisualParameters (int savePoint)
1842 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1843 if (!appStudy || !appStudy->studyDS())
1845 _PTR(Study) studyDS = appStudy->studyDS();
1847 // componentName is used for encoding of entries when storing them in IParameters
1848 std::string componentName = myComponentGeom->ComponentDataType();
1849 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1850 //if (!aSComponent) return;
1853 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1854 componentName.c_str(),
1856 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1858 std::vector<std::string> entries = ip->getEntries();
1860 for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1862 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1863 QString entry (ip->decodeEntry(*entIt).c_str());
1865 // Check that the entry corresponds to a real object in the Study
1866 // as the object may be deleted or modified after the visual state is saved.
1867 _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1868 if (!so) continue; //Skip the not existent entry
1870 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1871 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1873 std::vector<std::string>::iterator namesIt = paramNames.begin();
1874 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1876 // actors are stored in a map after displaying of them for
1877 // quicker access in the future: map < viewID to actor >
1878 NCollection_DataMap<int, GEOM_Actor* > vtkActors;
1879 NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1881 for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1883 // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1884 // '_' is used as separator and should not be used in viewer type or parameter names.
1885 QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1886 if (lst.size() != 3)
1889 QString viewerTypStr = lst[0];
1890 QString viewIndexStr = lst[1];
1891 QString paramNameStr = lst[2];
1894 int viewIndex = viewIndexStr.toUInt(&ok);
1895 if (!ok) // bad conversion of view index to integer
1899 if (viewerTypStr == SVTK_Viewer::Type())
1901 GEOM_Actor* vActor = 0;
1902 if (vtkActors.IsBound(viewIndex))
1903 vActor = vtkActors.Find(viewIndex);
1905 if (paramNameStr == "Visibility")
1907 if (!vActor && displayer())
1909 QList<SUIT_ViewManager*> lst;
1910 getApp()->viewManagers(viewerTypStr, lst);
1912 // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1913 if (viewIndex >= 0 && viewIndex < lst.count()) {
1914 SUIT_ViewManager* vman = lst.at(viewIndex);
1915 SUIT_ViewModel* vmodel = vman->getViewModel();
1916 // SVTK view model can be casted to SALOME_View
1917 displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1919 // store displayed actor in a temporary map for quicker
1920 // access later when restoring other parameters
1921 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1922 vtkRenderer* Renderer = vtkView->getRenderer();
1923 vtkActorCollection* theActors = Renderer->GetActors();
1924 theActors->InitTraversal();
1925 bool isFound = false;
1926 vtkActor *ac = theActors->GetNextActor();
1927 for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1928 if (ac->IsA("GEOM_Actor")) {
1929 GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1930 if (aGeomAc->hasIO()) {
1931 Handle(SALOME_InteractiveObject) io =
1932 Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1933 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1935 vtkActors.Bind(viewIndex, aGeomAc);
1942 } // if (paramNameStr == "Visibility")
1945 // the rest properties "work" with GEOM_Actor
1948 QString val ((*valuesIt).c_str());
1950 if (paramNameStr == "DisplayMode") {
1951 vActor->setDisplayMode(val.toInt());
1953 else if (paramNameStr == "Color") {
1954 QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1955 if (colors.count() == 3)
1956 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1958 else if (paramNameStr == "Opacity") {
1959 vActor->SetOpacity(val.toFloat());
1961 else if (paramNameStr == "Isos") {
1962 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1963 if (isos.count() == 2) {
1964 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1965 vActor->SetNbIsos(aIsos);
1969 } // other parameters than Visibility
1971 else if (viewerTypStr == SOCC_Viewer::Type())
1973 //Handle(AIS_InteractiveObject) occActor;
1974 Handle(GEOM_AISShape) occActor;
1975 if (occActors.IsBound(viewIndex))
1976 occActor = occActors.Find(viewIndex);
1978 // ViewModel and InteractiveContext
1979 SOCC_Viewer* occVModel = 0;
1980 Handle(AIS_InteractiveContext) ic;
1982 QList<SUIT_ViewManager*> lst;
1983 getApp()->viewManagers(viewerTypStr, lst);
1985 // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1986 if (viewIndex >= 0 && viewIndex < lst.count()) {
1987 SUIT_ViewManager* vman = lst.at(viewIndex);
1988 SUIT_ViewModel* vmodel = vman->getViewModel();
1989 occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1991 ic = occVModel->getAISContext();
1997 if (paramNameStr == "Visibility")
1999 if (occActor.IsNull() && displayer())
2001 displayer()->Display(entry, true, occVModel);
2003 // store displayed actor in a temporary map for quicker
2004 // access later when restoring other parameters
2005 AIS_ListOfInteractive aList;
2006 ic->DisplayedObjects(aList);
2007 bool isFound = false;
2008 AIS_ListIteratorOfListOfInteractive ite (aList);
2009 for (; ite.More() && !isFound; ite.Next()) {
2010 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
2011 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
2013 Handle(SALOME_InteractiveObject) io =
2014 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
2015 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
2017 occActors.Bind(viewIndex, aSh);
2023 } // if (paramNameStr == "Visibility")
2026 // the rest properties "work" with GEOM_AISShape
2027 if (!occActor.IsNull())
2029 QString val ((*valuesIt).c_str());
2031 if (paramNameStr == "DisplayMode") {
2032 ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
2033 //ic->Redisplay(occActor, Standard_False, Standard_True);
2035 // Color is restored by the GEOM engine
2036 else if (paramNameStr == "Transparency") {
2037 ic->SetTransparency(occActor, val.toFloat(), false);
2038 ic->Redisplay(occActor, Standard_False, Standard_True);
2040 else if (paramNameStr == "Isos") {
2041 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
2042 if (isos.count() == 2) {
2043 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
2044 int nbUIso = isos[0].toInt();
2045 int nbVIso = isos[1].toInt();
2046 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
2047 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
2048 uIsoAspect->SetNumber(nbUIso);
2049 vIsoAspect->SetNumber(nbVIso);
2050 aDrawer->SetUIsoAspect(uIsoAspect);
2051 aDrawer->SetVIsoAspect(vIsoAspect);
2052 ic->SetLocalAttributes(occActor, aDrawer);
2053 ic->Redisplay(occActor);
2057 } // other parameters than Visibility
2061 // unknown viewer type
2063 } // for names/parameters iterator
2064 } // for entries iterator
2066 // update all VTK and OCC views
2067 QList<SUIT_ViewManager*> lst;
2068 getApp()->viewManagers(lst);
2069 for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2070 SUIT_ViewModel* vmodel = (*it)->getViewModel();
2073 if (vmodel->getType() == SVTK_Viewer::Type()) {
2074 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2075 vtkView->getRenderer()->ResetCameraClippingRange();
2078 else if (vmodel->getType() == SOCC_Viewer::Type()) {
2079 //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2080 SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);
2087 void GeometryGUI::onViewAboutToShow()
2089 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
2090 QAction* a = action( 218 );
2092 a->setEnabled(true);
2093 bool vmode = window->getCustomData("VectorsMode").toBool();
2094 a->setText ( vmode == 1 ? tr( "MEN_VECTOR_MODE_OFF" ) : tr("MEN_VECTOR_MODE_ON") );
2096 a->setText ( tr("MEN_VECTOR_MODE_ON") );
2097 a->setEnabled(false);