1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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 // File : GeometryGUI.cxx
23 // 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>
84 #include <utilities.h>
86 #include <vtkCamera.h>
87 #include <vtkRenderer.h>
89 #include "GEOMImpl_Types.hxx"
94 Standard_EXPORT CAM_Module* createModule() {
95 return new GeometryGUI();
101 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
103 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
105 // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
106 if (CORBA::is_nil(myComponentGeom))
108 return GeometryGUI::myComponentGeom;
111 bool GeometryGUI::InitGeomGen()
114 if( CORBA::is_nil( myComponentGeom ) ) return false;
118 //=======================================================================
119 // function : ClientSObjectToObject
121 //=======================================================================
122 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
124 _PTR(GenericAttribute) anAttr;
125 CORBA::Object_var anObj;
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());
133 INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
135 return anObj._retn();
138 //=======================================================================
139 // function : ClientStudyToStudy
141 //=======================================================================
142 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
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();
152 //=======================================================================
153 // function : GeometryGUI::GeometryGUI()
154 // purpose : Constructor
155 //=======================================================================
156 GeometryGUI::GeometryGUI() :
157 SalomeApp_Module( "GEOM" )
159 if ( CORBA::is_nil( myComponentGeom ) )
161 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
162 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
163 myComponentGeom = GEOM::GEOM_Gen::_narrow( comp );
167 myActiveDialogBox = 0;
170 gp_Pnt origin = gp_Pnt(0., 0., 0.);
171 gp_Dir direction = gp_Dir(0., 0., 1.);
172 myWorkingPlane = gp_Ax3(origin, direction);
175 myLocalSelectionMode = GEOM_ALLOBJECTS;
178 //=======================================================================
179 // function : GeometryGUI::~GeometryGUI()
180 // purpose : Destructor
181 //=======================================================================
182 GeometryGUI::~GeometryGUI()
184 while (!myOCCSelectors.isEmpty())
185 delete myOCCSelectors.takeFirst();
187 while (!myVTKSelectors.isEmpty())
188 delete myVTKSelectors.takeFirst();
191 //=======================================================================
192 // function : GeometryGUI::getLibrary()
193 // purpose : get or load GUI library by name [ internal ]
194 //=======================================================================
195 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
196 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
198 if ( !myGUIMap.contains( libraryName ) ) {
199 // try to load library if it is not loaded yet
202 libs = getenv( "LD_LIBRARY_PATH" );
203 if( !libs.isEmpty() ) {
204 QStringList dirList = libs.split( ":", QString::SkipEmptyParts ); // skip empty entries
206 libs = getenv( "PATH" );
207 if( !libs.isEmpty() ) {
208 QStringList dirList = libs.split( ";", QString::SkipEmptyParts ); // skip empty entries
210 for( int i = dirList.count()-1; i >= 0; i-- ) {
211 QString dir = dirList[ i ];
212 QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
214 OSD_SharedLibrary aSharedLibrary( fi.fileName().toLatin1().data() );
215 bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
217 MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
218 continue; // continue search further
220 OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
221 if ( osdF != NULL ) {
222 LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
223 GEOMGUI* libGUI = (*func)(this);
225 myGUIMap[ libraryName ] = libGUI;
226 break; // found and loaded!
233 if ( myGUIMap.contains( libraryName ) )
234 // library is successfully loaded
235 return myGUIMap[ libraryName ];
239 //=======================================================================
240 // function : GeometryGUI::ActiveWorkingPlane()
241 // purpose : Activate Working Plane View
242 //=======================================================================
243 void GeometryGUI::ActiveWorkingPlane()
245 gp_Dir DZ = myWorkingPlane.Direction();
246 gp_Dir DY = myWorkingPlane.YDirection();
248 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
249 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
250 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
253 OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
255 Handle(V3d_View) view3d = vw->getViewPort()->getView();
257 view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
258 view3d->SetUp(DY.X(), DY.Y(), DY.Z());
264 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
266 vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
268 camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
269 camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
270 camera->SetFocalPoint(0,0,0);
277 //=======================================================================
278 // function : GeometryGUI::SetActiveDialogBox()
279 // purpose : Set active dialog box
280 //=======================================================================
281 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
283 myActiveDialogBox = (QDialog*)aDlg;
286 //=======================================================================
287 // function : GeometryGUI::EmitSignalDeactivateDialog()
288 // purpose : Emit a signal to deactivate the active dialog Box
289 //=======================================================================
290 void GeometryGUI::EmitSignalDeactivateDialog()
292 emit SignalDeactivateActiveDialog();
295 //=======================================================================
296 // function : GeometryGUI::EmitSignalCloseAllDialogs()
297 // purpose : Emit a signal to close all non modal dialogs box
298 //=======================================================================
299 void GeometryGUI::EmitSignalCloseAllDialogs()
301 emit SignalCloseAllDialogs();
304 //=======================================================================
305 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
306 // purpose : Emit a signal to inform that default real spin box step has
308 //=======================================================================
309 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
311 emit SignalDefaultStepValueChanged(newVal);
314 //=======================================================================
315 // function : GeometryGUI::OnGUIEvent()
316 // purpose : common slot for all menu/toolbar actions
317 //=======================================================================
318 void GeometryGUI::OnGUIEvent()
320 const QObject* obj = sender();
321 if ( !obj || !obj->inherits( "QAction" ) )
323 int id = actionId((QAction*)obj);
328 //=======================================================================
329 // function : GeometryGUI::OnGUIEvent()
330 // purpose : manage all events on GUI [static]
331 //=======================================================================
332 void GeometryGUI::OnGUIEvent( int id )
334 SUIT_Application* anApp = application();
336 SUIT_Desktop* desk = anApp->desktop();
338 // check type of the active viewframe
339 SUIT_ViewWindow* window = desk->activeWindow();
340 bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
341 bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
342 // if current viewframe is not of OCC and not of VTK type - return immediately
343 // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
344 bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
345 if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
348 // fix for IPAL9103, point 2
349 if ( CORBA::is_nil( GetGeomGen() ) ) {
350 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
354 GEOMGUI* library = 0;
355 // try to get-or-load corresponding GUI library
356 if( id == 111 || // MENU FILE - IMPORT BREP
357 id == 112 || // MENU FILE - IMPORT IGES
358 id == 113 || // MENU FILE - IMPORT STEP
359 id == 121 || // MENU FILE - EXPORT BREP
360 id == 122 || // MENU FILE - EXPORT IGES
361 id == 123 || // MENU FILE - EXPORT STEP
362 id == 2171 || // POPUP VIEWER - SELECT ONLY - VERTEX
363 id == 2172 || // POPUP VIEWER - SELECT ONLY - EDGE
364 id == 2173 || // POPUP VIEWER - SELECT ONLY - WIRE
365 id == 2174 || // POPUP VIEWER - SELECT ONLY - FACE
366 id == 2175 || // POPUP VIEWER - SELECT ONLY - SHELL
367 id == 2176 || // POPUP VIEWER - SELECT ONLY - SOLID
368 id == 2177 || // POPUP VIEWER - SELECT ONLY - COMPOUND
369 id == 2178 || // POPUP VIEWER - SELECT ONLY - SELECT ALL
370 id == 31 || // MENU EDIT - COPY
371 id == 33 || // MENU EDIT - DELETE
372 id == 411 || // MENU SETTINGS - ADD IN STUDY
373 id == 412 || // MENU SETTINGS - SHADING COLOR
374 id == 5103 || // MENU TOOLS - CHECK GEOMETRY
375 id == 8032 || // POPUP VIEWER - COLOR
376 id == 8033 || // POPUP VIEWER - TRANSPARENCY
377 id == 8034 || // POPUP VIEWER - ISOS
378 id == 8035 || // POPUP VIEWER - AUTO COLOR
379 id == 8036 || // POPUP VIEWER - DISABLE AUTO COLOR
380 id == 804 || // POPUP VIEWER - ADD IN STUDY
381 id == 901 || // OBJECT BROWSER - RENAME
382 id == 9024 ) { // OBJECT BROWSER - OPEN
383 //cout << "id " << id << " received" << endl;
385 library = getLibrary( "libGEOMToolsGUI.so" );
387 library = getLibrary( "GEOMToolsGUI.dll" );
390 else if( id == 211 || // MENU VIEW - WIREFRAME/SHADING
391 id == 212 || // MENU VIEW - DISPLAY ALL
392 id == 213 || // MENU VIEW - DISPLAY ONLY
393 id == 214 || // MENU VIEW - ERASE ALL
394 id == 215 || // MENU VIEW - ERASE
395 id == 216 || // MENU VIEW - DISPLAY
396 id == 80311 || // POPUP VIEWER - WIREFRAME
397 id == 80312 ) { // POPUP VIEWER - SHADING
399 library = getLibrary( "libDisplayGUI.so" );
401 library = getLibrary( "DisplayGUI.dll" );
404 else if( id == 4011 || // MENU BASIC - POINT
405 id == 4012 || // MENU BASIC - LINE
406 id == 4013 || // MENU BASIC - CIRCLE
407 id == 4014 || // MENU BASIC - ELLIPSE
408 id == 4015 || // MENU BASIC - ARC
409 id == 4016 || // MENU BASIC - VECTOR
410 id == 4017 || // MENU BASIC - PLANE
411 id == 4018 || // MENU BASIC - WPLANE
412 id == 4019 || // MENU BASIC - CURVE
413 id == 4020 ) { // MENU BASIC - REPAIR
415 library = getLibrary( "libBasicGUI.so" );
417 library = getLibrary( "BasicGUI.dll" );
420 else if( id == 4021 || // MENU PRIMITIVE - BOX
421 id == 4022 || // MENU PRIMITIVE - CYLINDER
422 id == 4023 || // MENU PRIMITIVE - SPHERE
423 id == 4024 || // MENU PRIMITIVE - TORUS
424 id == 4025 || // MENU PRIMITIVE - CONE
425 id == 4026 || // MENU PRIMITIVE - FACE
426 id == 4027 ) { // MENU PRIMITIVE - DISK
428 library = getLibrary( "libPrimitiveGUI.so" );
430 library = getLibrary( "PrimitiveGUI.dll" );
433 else if( id == 4031 || // MENU GENERATION - PRISM
434 id == 4032 || // MENU GENERATION - REVOLUTION
435 id == 4033 || // MENU GENERATION - FILLING
436 id == 4034 ) { // MENU GENERATION - PIPE
438 library = getLibrary( "libGenerationGUI.so" );
440 library = getLibrary( "GenerationGUI.dll" );
443 else if( id == 404 || // MENU ENTITY - SKETCHER
444 id == 407 ) { // MENU ENTITY - EXPLODE
446 library = getLibrary( "libEntityGUI.so" );
448 library = getLibrary( "EntityGUI.dll" );
451 else if( id == 4081 || // MENU BUILD - EDGE
452 id == 4082 || // MENU BUILD - WIRE
453 id == 4083 || // MENU BUILD - FACE
454 id == 4084 || // MENU BUILD - SHELL
455 id == 4085 || // MENU BUILD - SOLID
456 id == 4086 ) { // MENU BUILD - COMPUND
458 library = getLibrary( "libBuildGUI.so" );
460 library = getLibrary( "BuildGUI.dll" );
463 else if( id == 5011 || // MENU BOOLEAN - FUSE
464 id == 5012 || // MENU BOOLEAN - COMMON
465 id == 5013 || // MENU BOOLEAN - CUT
466 id == 5014 ) { // MENU BOOLEAN - SECTION
468 library = getLibrary( "libBooleanGUI.so" );
470 library = getLibrary( "BooleanGUI.dll" );
473 else if( id == 5021 || // MENU TRANSFORMATION - TRANSLATION
474 id == 5022 || // MENU TRANSFORMATION - ROTATION
475 id == 5023 || // MENU TRANSFORMATION - LOCATION
476 id == 5024 || // MENU TRANSFORMATION - MIRROR
477 id == 5025 || // MENU TRANSFORMATION - SCALE
478 id == 5026 || // MENU TRANSFORMATION - OFFSET
479 id == 5027 || // MENU TRANSFORMATION - MULTI-TRANSLATION
480 id == 5028 || // MENU TRANSFORMATION - MULTI-ROTATION
481 id == 5029 ) { // CONTEXT(POPUP) MENU - RELOAD_IMPORTED
483 library = getLibrary( "libTransformationGUI.so" );
485 library = getLibrary( "TransformationGUI.dll" );
488 else if( id == 503 || // MENU OPERATION - PARTITION
489 id == 504 || // MENU OPERATION - ARCHIMEDE
490 id == 505 || // MENU OPERATION - FILLET
491 id == 506 || // MENU OPERATION - CHAMFER
492 id == 507 || // MENU OPERATION - CLIPPING RANGE
493 id == 508 ) { // MENU OPERATION - GET SHAPES ON SHAPE
495 library = getLibrary( "libOperationGUI.so" );
497 library = getLibrary( "OperationGUI.dll" );
500 else if( id == 601 || // MENU REPAIR - SEWING
501 id == 603 || // MENU REPAIR - SUPPRESS FACES
502 id == 604 || // MENU REPAIR - SUPPRESS HOLE
503 id == 605 || // MENU REPAIR - SHAPE PROCESSING
504 id == 606 || // MENU REPAIR - CLOSE CONTOUR
505 id == 607 || // MENU REPAIR - REMOVE INTERNAL WIRES
506 id == 608 || // MENU REPAIR - ADD POINT ON EDGE
507 id == 609 || // MENU MEASURE - FREE BOUNDARIES
508 id == 610 || // MENU MEASURE - FREE FACES
509 id == 611 || // MENU REPAIR - CHANGE ORIENTATION
510 id == 602 || // MENU REPAIR - GLUE FACES
511 id == 612 ) { // MENU REPAIR - REMOVE EXTRA EDGES
513 library = getLibrary( "libRepairGUI.so" );
515 library = getLibrary( "RepairGUI.dll" );
518 else if( id == 701 || // MENU MEASURE - PROPERTIES
519 id == 702 || // MENU MEASURE - CDG
520 id == 703 || // MENU MEASURE - INERTIA
521 id == 704 || // MENU MEASURE - NORMALE
522 id == 7041 || // MENU MEASURE - BOUNDING BOX
523 id == 7042 || // MENU MEASURE - MIN DISTANCE
524 id == 7043 || // MENU MEASURE - ANGLE
525 id == 705 || // MENU MEASURE - TOLERANCE
526 id == 706 || // MENU MEASURE - WHATIS
527 id == 707 || // MENU MEASURE - CHECK
528 id == 7072 || // MENU MEASURE - CHECK COMPOUND OF BLOCKS
529 id == 708 ) { // MENU MEASURE - POINT COORDINATES
531 library = getLibrary( "libMeasureGUI.so" );
533 library = getLibrary( "MeasureGUI.dll" );
536 else if( id == 800 || // MENU GROUP - CREATE
537 id == 8001 || // POPUP MENU - CREATE GROUP
538 id == 801 ) { // MENU GROUP - EDIT
540 library = getLibrary( "libGroupGUI.so" );
542 library = getLibrary( "GroupGUI.dll" );
545 else if( id == 9999 || // MENU BLOCKS - HEXAHEDRAL SOLID
546 id == 9998 || // MENU BLOCKS - MULTI-TRANSFORMATION
547 id == 9997 || // MENU BLOCKS - QUADRANGLE FACE
548 id == 99991 || // MENU BLOCKS - PROPAGATE
549 id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
551 library = getLibrary( "libBlocksGUI.so" );
553 library = getLibrary( "BlocksGUI.dll" );
557 // call method of corresponding GUI library
559 library->OnGUIEvent( id, desk );
561 SUIT_MessageBox::critical( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
565 //=================================================================================
566 // function : GeometryGUI::OnKeyPress()
567 // purpose : Called when any key is pressed by user [static]
568 //=================================================================================
569 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
573 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
574 SUIT_Application* anApp = application();
576 bOk = bOk && it.value()->OnKeyPress( pe, anApp->desktop(), win );
582 //=================================================================================
583 // function : GeometryGUI::OnMouseMove()
584 // purpose : Manages mouse move events [static]
585 //=================================================================================
586 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
590 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
591 SUIT_Application* anApp = application();
593 bOk = bOk && it.value()->OnMouseMove( pe, anApp->desktop(), win );
599 //=================================================================================
600 // function : GeometryGUI::0nMousePress()
601 // purpose : Manage mouse press events [static]
602 //=================================================================================
603 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
606 // OnMousePress() should return false if this event should be processed further
607 // (see OCCViewer_Viewer3d::onMousePress() for explanation)
608 bool processed = false;
609 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
610 SUIT_Application* anApp = application();
612 processed = processed || it.value()->OnMousePress( pe, anApp->desktop(), win );
618 static void UpdateVtkSelection()
620 QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
621 SUIT_ViewWindow* win = 0;
622 for ( win = winList.first(); win; win = winList.next() ) {
623 if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
624 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
626 SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
627 anInteractor->SetSelectionProp();
628 anInteractor->SetSelectionTolerance();
629 SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
631 aStyle->setPreselectionProp();
638 //=================================================================================
639 // function : GeometryGUI::SetSettings()
640 // purpose : Called when GEOM module is activated [static]
641 //=================================================================================
642 bool GeometryGUI::SetSettings()
644 QMenuBar* Mb = parent->getMainMenuBar();
645 SUIT_Study* ActiveStudy = application()->activeStudy();
647 // Wireframe or Shading
649 SUIT_ViewWindow* window = application()->desktop()->activeWindow();
650 bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
651 bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
653 OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
655 Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
656 DisplayMode = ic->DisplayMode();
659 else if ( ViewVTK ) {
660 SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
662 SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
663 DisplayMode = myRenderInter->GetDisplayMode();
667 if( DisplayMode == 1 )
669 Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
671 Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
674 // Add in Study - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
675 QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
676 int Settings_AddInStudy;
677 // if(!AddInStudy.isEmpty())
678 // Settings_AddInStudy = AddInStudy.toInt();
681 Settings_AddInStudy = 1;
682 Mb->setItemChecked(411, Settings_AddInStudy);
685 QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
687 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
690 int count = ActiveStudy->getStudyFramesCount();
691 for(int i = 0; i < count; i++) {
692 if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
693 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
694 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
696 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
697 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
699 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
701 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
707 // PAL5356: update VTK selection
708 ::UpdateVtkSelection();
711 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
712 bOk = bOk && it.data()->SetSettings( parent );
714 // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
715 if (getenv( "GEOM_CLIPPING" ) == NULL)
717 QMenuItem* mi = Mb->findItem(50);
718 if (mi && mi->popup())
719 mi->popup()->removeItem(507);
726 //=======================================================================
727 // function : createGeomAction
729 //=======================================================================
730 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle )
733 QWidget* parent = application()->desktop();
734 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
736 if ( icon_id.length() )
737 pix = resMgr->loadPixmap( "GEOM", tr( icon_id.toLatin1().constData() ) );
739 pix = resMgr->loadPixmap( "GEOM", tr( (QString( "ICO_" )+po_id).toLatin1().constData() ), false );
743 QString tooltip = tr( (QString( "TOP_" )+po_id).toLatin1().constData() ),
744 menu = tr( (QString( "MEN_" )+po_id).toLatin1().constData() ),
745 status_bar = tr( (QString( "STB_" )+po_id).toLatin1().constData() );
747 createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() ) );
752 //=======================================================================
753 // function : GeometryGUI::initialize()
754 // purpose : Called when GEOM module is created
755 //=======================================================================
756 void GeometryGUI::initialize( CAM_Application* app )
758 SalomeApp_Module::initialize( app );
760 // ----- create actions --------------
762 createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
763 createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
765 createGeomAction( 33, "DELETE", "", Qt::Key_Delete );
767 createGeomAction( 4011, "POINT" );
768 createGeomAction( 4012, "LINE" );
769 createGeomAction( 4013, "CIRCLE" );
770 createGeomAction( 4014, "ELLIPSE" );
771 createGeomAction( 4015, "ARC" );
772 createGeomAction( 4019, "CURVE" );
773 createGeomAction( 4016, "VECTOR" );
774 createGeomAction( 4017, "PLANE" );
775 createGeomAction( 4018, "WORK_PLANE" );
776 createGeomAction( 4020, "LOCAL_CS" );
778 createGeomAction( 4021, "BOX" );
779 createGeomAction( 4022, "CYLINDER" );
780 createGeomAction( 4023, "SPHERE" );
781 createGeomAction( 4024, "TORUS" );
782 createGeomAction( 4025, "CONE" );
783 createGeomAction( 4026, "FACE" );
784 createGeomAction( 4027, "DISK" );
786 createGeomAction( 4031, "EXTRUSION" );
787 createGeomAction( 4032, "REVOLUTION" );
788 createGeomAction( 4033, "FILLING" );
789 createGeomAction( 4034, "PIPE" );
791 createGeomAction( 800, "GROUP_CREATE" );
792 createGeomAction( 801, "GROUP_EDIT" );
794 createGeomAction( 5029, "RELOAD_IMPORTED" );
796 createGeomAction( 9997, "Q_FACE" );
797 createGeomAction( 9999, "HEX_SOLID" );
799 createGeomAction( 404, "SKETCH" );
800 createGeomAction( 407, "EXPLODE" );
802 createGeomAction( 4081, "EDGE" );
803 createGeomAction( 4082, "WIRE" );
804 createGeomAction( 4083, "FACE" );
805 createGeomAction( 4084, "SHELL" );
806 createGeomAction( 4085, "SOLID" );
807 createGeomAction( 4086, "COMPOUND" );
809 createGeomAction( 5011, "FUSE" );
810 createGeomAction( 5012, "COMMON" );
811 createGeomAction( 5013, "CUT" );
812 createGeomAction( 5014, "SECTION" );
814 createGeomAction( 5021, "TRANSLATION" );
815 createGeomAction( 5022, "ROTATION" );
816 createGeomAction( 5023, "MODIFY_LOCATION" );
817 createGeomAction( 5024, "MIRROR" );
818 createGeomAction( 5025, "SCALE" );
819 createGeomAction( 5026, "OFFSET" );
820 createGeomAction( 5027, "MUL_TRANSLATION" );
821 createGeomAction( 5028, "MUL_ROTATION" );
823 createGeomAction( 503, "PARTITION" );
824 createGeomAction( 504, "ARCHIMEDE" );
825 createGeomAction( 505, "FILLET" );
826 createGeomAction( 506, "CHAMFER" );
827 //createGeomAction( 507, "CLIPPING" );
828 createGeomAction( 508, "GET_SHAPES_ON_SHAPES" );
830 createGeomAction( 9998, "MUL_TRANSFORM" );
831 createGeomAction( 9995, "EXPLODE_BLOCKS" );
832 createGeomAction( 99991, "PROPAGATE" );
834 createGeomAction( 601, "SEWING" );
835 createGeomAction( 602, "GLUE_FACES" );
836 createGeomAction( 603, "SUPPRESS_FACES" );
837 createGeomAction( 604, "SUPPERSS_HOLES" );
838 createGeomAction( 605, "SHAPE_PROCESS" );
839 createGeomAction( 606, "CLOSE_CONTOUR" );
840 createGeomAction( 607, "SUPPRESS_INT_WIRES" );
841 createGeomAction( 608, "POINT_ON_EDGE" );
842 createGeomAction( 609, "CHECK_FREE_BNDS" );
843 createGeomAction( 610, "CHECK_FREE_FACES" );
844 createGeomAction( 611, "CHANGE_ORIENTATION" );
845 createGeomAction( 612, "REMOVE_EXTRA_EDGES" );
847 createGeomAction( 708, "POINT_COORDS" );
848 createGeomAction( 701, "BASIC_PROPS" );
849 createGeomAction( 702, "MASS_CENTER" );
850 createGeomAction( 703, "INERTIA" );
851 createGeomAction( 704, "NORMALE" );
852 createGeomAction( 7041, "BND_BOX" );
853 createGeomAction( 7042, "MIN_DIST" );
854 createGeomAction( 7043, "MEASURE_ANGLE" );
856 createGeomAction( 705, "TOLERANCE" );
857 createGeomAction( 706, "WHAT_IS" );
858 createGeomAction( 707, "CHECK" );
859 createGeomAction( 7072, "CHECK_COMPOUND" );
861 #ifdef _DEBUG_ // PAL16821
862 createGeomAction( 5103, "CHECK_GEOMETRY" );
864 createGeomAction( 412, "SHADING_COLOR" );
866 createGeomAction( 211, "SHADING" );
867 createGeomAction( 212, "DISPLAY_ALL" );
868 createGeomAction( 214, "ERASE_ALL" );
869 createGeomAction( 216, "DISPLAY" );
870 createGeomAction( 2171, "VERTEX_SEL_ONLY" ,"", 0, true );
871 createGeomAction( 2172, "EDGE_SEL_ONLY", "", 0, true );
872 createGeomAction( 2173, "WIRE_SEL_ONLY", "", 0, true );
873 createGeomAction( 2174, "FACE_SEL_ONLY", "", 0, true );
874 createGeomAction( 2175, "SHELL_SEL_ONLY", "", 0, true );
875 createGeomAction( 2176, "SOLID_SEL_ONLY", "", 0, true );
876 createGeomAction( 2177, "COMPOUND_SEL_ONLY", "", 0, true );
877 createGeomAction( 2178, "ALL_SEL_ONLY", "", 0, true );
878 createGeomAction( 213, "DISPLAY_ONLY" );
879 createGeomAction( 215, "ERASE" );
881 createGeomAction( 901, "POP_RENAME", "", Qt::Key_F2 );
882 createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
883 createGeomAction( 80312, "POP_SHADING", "", 0, true );
884 createGeomAction( 8032, "POP_COLOR" );
885 createGeomAction( 8033, "POP_TRANSPARENCY" );
886 createGeomAction( 8034, "POP_ISOS" );
887 createGeomAction( 8035, "POP_AUTO_COLOR" );
888 createGeomAction( 8036, "POP_DISABLE_AUTO_COLOR" );
889 createGeomAction( 8001, "POP_CREATE_GROUP" );
891 // make wireframe-shading items to be exclusive (only one at a time is selected)
892 //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
893 //dispModeGr->add( action( 80311 ) );
894 //dispModeGr->add( action( 80312 ) );
895 // ---- create menu --------------------------
897 int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
898 createMenu( separator(), fileId, 10 );
899 createMenu( 111, fileId, 10 );
900 createMenu( 121, fileId, 10 );
901 createMenu( separator(), fileId, -1 );
903 int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
904 createMenu( 33, editId, -1 );
906 int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
908 int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
909 createMenu( 4011, basicId, -1 );
910 createMenu( 4012, basicId, -1 );
911 createMenu( 4013, basicId, -1 );
912 createMenu( 4014, basicId, -1 );
913 createMenu( 4015, basicId, -1 );
914 createMenu( 4019, basicId, -1 );
915 createMenu( separator(), basicId, -1 );
916 createMenu( 4016, basicId, -1 );
917 createMenu( 4017, basicId, -1 );
918 createMenu( 4018, basicId, -1 );
919 createMenu( 4020, basicId, -1 );
921 int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
922 createMenu( 4021, primId, -1 );
923 createMenu( 4022, primId, -1 );
924 createMenu( 4023, primId, -1 );
925 createMenu( 4024, primId, -1 );
926 createMenu( 4025, primId, -1 );
927 createMenu( 4026, primId, -1 );
928 createMenu( 4027, primId, -1 );
930 int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
931 createMenu( 4031, genId, -1 );
932 createMenu( 4032, genId, -1 );
933 createMenu( 4033, genId, -1 );
934 createMenu( 4034, genId, -1 );
935 createMenu( separator(), newEntId, -1 );
937 int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
938 createMenu( 800, groupId, -1 );
939 createMenu( 801, groupId, -1 );
940 createMenu( separator(), newEntId, -1 );
942 int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
943 createMenu( 9997, blocksId, -1 );
944 createMenu( 9999, blocksId, -1 );
946 createMenu( separator(), newEntId, -1 );
947 createMenu( 404, newEntId, -1 );
948 createMenu( separator(), newEntId, -1 );
949 createMenu( 407, newEntId, -1 );
951 int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
952 createMenu( 4081, buildId, -1 );
953 createMenu( 4082, buildId, -1 );
954 createMenu( 4083, buildId, -1 );
955 createMenu( 4084, buildId, -1 );
956 createMenu( 4085, buildId, -1 );
957 createMenu( 4086, buildId, -1 );
959 int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
961 int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
962 createMenu( 5011, boolId, -1 );
963 createMenu( 5012, boolId, -1 );
964 createMenu( 5013, boolId, -1 );
965 createMenu( 5014, boolId, -1 );
967 int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
968 createMenu( 5021, transId, -1 );
969 createMenu( 5022, transId, -1 );
970 createMenu( 5023, transId, -1 );
971 createMenu( 5024, transId, -1 );
972 createMenu( 5025, transId, -1 );
973 createMenu( 5026, transId, -1 );
974 createMenu( separator(), transId, -1 );
975 createMenu( 5027, transId, -1 );
976 createMenu( 5028, transId, -1 );
978 createMenu( 503, operId, -1 );
979 createMenu( 504, operId, -1 );
980 createMenu( 508, operId, -1 );
981 createMenu( separator(), operId, -1 );
982 createMenu( 505, transId, -1 );
983 createMenu( 506, transId, -1 );
984 //createMenu( 507, transId, -1 );
986 int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
987 createMenu( 9998, blockId, -1 );
988 createMenu( 9995, blockId, -1 );
989 createMenu( 99991, blockId, -1 );
991 int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
992 createMenu( 605, repairId, -1 );
993 createMenu( 603, repairId, -1 );
994 createMenu( 606, repairId, -1 );
995 createMenu( 607, repairId, -1 );
996 createMenu( 604, repairId, -1 );
997 createMenu( 601, repairId, -1 );
998 createMenu( 602, repairId, -1 );
999 createMenu( 608, repairId, -1 );
1000 //createMenu( 609, repairId, -1 );
1001 //createMenu( 610, repairId, -1 );
1002 createMenu( 611, repairId, -1 );
1003 createMenu( 612, repairId, -1 );
1005 int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
1006 createMenu( 708, measurId, -1 );
1007 createMenu( 701, measurId, -1 );
1008 createMenu( separator(), measurId, -1 );
1009 createMenu( 702, measurId, -1 );
1010 createMenu( 703, measurId, -1 );
1011 createMenu( 704, measurId, -1 );
1012 // NPAL16572: move "Check free boundaries" and "Check free faces" from "Repair" to "Measure"
1013 createMenu( separator(), measurId, -1 );
1014 createMenu( 609, measurId, -1 );
1015 createMenu( 610, measurId, -1 );
1017 createMenu( separator(), measurId, -1 );
1019 int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
1020 createMenu( 7041, dimId, -1 );
1021 createMenu( 7042, dimId, -1 );
1022 createMenu( 7043, dimId, -1 );
1023 createMenu( separator(), measurId, -1 );
1025 createMenu( 705, measurId, -1 );
1026 createMenu( separator(), measurId, -1 );
1027 createMenu( 706, measurId, -1 );
1028 createMenu( 707, measurId, -1 );
1029 createMenu( 7072, measurId, -1 );
1031 #ifdef _DEBUG_ // PAL16821
1032 int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
1033 createMenu( separator(), toolsId, -1 );
1034 createMenu( 5103, toolsId, -1 );
1036 //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
1037 //createMenu( separator(), prefId, -1 );
1038 //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
1039 //createMenu( 412, geomId, -1 );
1040 //createMenu( separator(), prefId, -1 );
1042 int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1043 createMenu( separator(), viewId, -1 );
1045 int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1046 createMenu( 211, dispmodeId, -1 );
1048 createMenu( separator(), viewId, -1 );
1049 createMenu( 212, viewId, -1 );
1050 createMenu( 214, viewId, -1 );
1051 createMenu( separator(), viewId, -1 );
1055 because of these items are accessible through object browser and viewers
1056 we have removed they from main menu
1058 createMenu( 216, viewId, -1 );
1059 createMenu( 213, viewId, -1 );
1060 createMenu( 215, viewId, -1 );
1063 // ---- create toolbars --------------------------
1065 int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1066 createTool( 4011, basicTbId );
1067 createTool( 4012, basicTbId );
1068 createTool( 4013, basicTbId );
1069 createTool( 4014, basicTbId );
1070 createTool( 4015, basicTbId );
1071 createTool( 4019, basicTbId );
1072 createTool( 4016, basicTbId );
1073 createTool( 4017, basicTbId );
1074 createTool( 4018, basicTbId );
1075 createTool( 4020, basicTbId );
1077 int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1078 createTool( 4021, primTbId );
1079 createTool( 4022, primTbId );
1080 createTool( 4023, primTbId );
1081 createTool( 4024, primTbId );
1082 createTool( 4025, primTbId );
1083 createTool( 4026, primTbId );
1084 createTool( 4027, primTbId );
1086 int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1087 createTool( 5011, boolTbId );
1088 createTool( 5012, boolTbId );
1089 createTool( 5013, boolTbId );
1090 createTool( 5014, boolTbId );
1092 int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1093 createTool( 4031, genTbId );
1094 createTool( 4032, genTbId );
1095 createTool( 4033, genTbId );
1096 createTool( 4034, genTbId );
1098 int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1099 createTool( 5021, transTbId );
1100 createTool( 5022, transTbId );
1101 createTool( 5023, transTbId );
1102 createTool( 5024, transTbId );
1103 createTool( 5025, transTbId );
1104 createTool( 5026, transTbId );
1105 createTool( separator(), transTbId );
1106 createTool( 5027, transTbId );
1107 createTool( 5028, transTbId );
1109 // ---- create popup menus --------------------------
1111 QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1112 QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1114 QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
1115 QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
1117 QString autoColorPrefix =
1118 "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
1120 QtxPopupMgr* mgr = popupMgr();
1121 mgr->insert( action( 901 ), -1, -1 ); // rename
1122 mgr->setRule( action( 901 ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
1123 mgr->insert( action( 33 ), -1, -1 ); // delete
1124 mgr->setRule( action( 33 ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
1125 mgr->insert( action( 8001 ), -1, -1 ); // create group
1126 mgr->setRule( action( 8001 ), QString("client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1127 mgr->insert( action( 801 ), -1, -1 ); // edit group
1128 mgr->setRule( action( 801 ), QString("client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true"), QtxPopupMgr::VisibleRule );
1129 mgr->insert( separator(), -1, -1 ); // -----------
1130 dispmodeId = mgr->insert( tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1131 mgr->insert( action( 80311 ), dispmodeId, -1 ); // wireframe
1132 mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1133 mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", QtxPopupMgr::ToggleRule );
1134 mgr->insert( action( 80312 ), dispmodeId, -1 ); // shading
1135 mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1136 mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
1137 mgr->insert( separator(), -1, -1 ); // -----------
1138 mgr->insert( action( 8032 ), -1, -1 ); // color
1139 mgr->setRule( action( 8032 ), clientOCCorVTKorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
1140 mgr->insert( action( 8033 ), -1, -1 ); // transparency
1141 mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
1142 mgr->insert( action( 8034 ), -1, -1 ); // isos
1143 mgr->setRule( action( 8034 ), clientOCCorVTK_AndSomeVisible + " and selcount>0 and isVisible", QtxPopupMgr::VisibleRule );
1144 mgr->insert( separator(), -1, -1 ); // -----------
1145 mgr->insert( action( 8035 ), -1, -1 ); // auto color
1146 mgr->setRule( action( 8035 ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
1147 mgr->insert( action( 8036 ), -1, -1 ); // disable auto color
1148 mgr->setRule( action( 8036 ), autoColorPrefix + " and isAutoColor=true", QtxPopupMgr::VisibleRule );
1149 mgr->insert( separator(), -1, -1 ); // -----------
1152 QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1153 onlyComponent = "((type='Component') and selcount=1)",
1154 rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1155 types = "'Shape' 'Group'";
1157 mgr->insert( action( 216 ), -1, -1 ); // display
1158 mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), QtxPopupMgr::VisibleRule );
1160 mgr->insert( action( 215 ), -1, -1 ); // erase
1161 mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), QtxPopupMgr::VisibleRule );
1163 mgr->insert( action( 214 ), -1, -1 ); // erase All
1164 mgr->setRule( action( 214 ), clientOCCorVTK, QtxPopupMgr::VisibleRule );
1166 QString selectOnly = "(client='OCCViewer' or client='VTKViewer') and (selcount=0)";
1168 int selectolnyId = mgr->insert( tr("MEN_SELECT_ONLY"), -1, -1); //select only menu
1169 mgr->insert( action(2171), selectolnyId, -1); //Vertex
1170 mgr->setRule(action(2171), selectOnly, QtxPopupMgr::VisibleRule);
1171 mgr->setRule(action(2171), selectOnly + " and selectionmode='VERTEX'", QtxPopupMgr::ToggleRule);
1172 mgr->insert( action(2172), selectolnyId, -1); //Edge
1173 mgr->setRule(action(2172), selectOnly, QtxPopupMgr::VisibleRule);
1174 mgr->setRule(action(2172), selectOnly + " and selectionmode='EDGE'", QtxPopupMgr::ToggleRule);
1175 mgr->insert( action(2173), selectolnyId, -1); //Wire
1176 mgr->setRule(action(2173), selectOnly, QtxPopupMgr::VisibleRule);
1177 mgr->setRule(action(2173), selectOnly + " and selectionmode='WIRE'", QtxPopupMgr::ToggleRule);
1178 mgr->insert( action(2174), selectolnyId, -1); //Face
1179 mgr->setRule(action(2174), selectOnly, QtxPopupMgr::VisibleRule);
1180 mgr->setRule(action(2174), selectOnly + " and selectionmode='FACE'", QtxPopupMgr::ToggleRule);
1181 mgr->insert( action(2175), selectolnyId, -1); //Shell
1182 mgr->setRule(action(2175), selectOnly, QtxPopupMgr::VisibleRule);
1183 mgr->setRule(action(2175), selectOnly + " and selectionmode='SHELL'", QtxPopupMgr::ToggleRule);
1184 mgr->insert( action(2176), selectolnyId, -1); //Solid
1185 mgr->setRule(action(2176), selectOnly, QtxPopupMgr::VisibleRule);
1186 mgr->setRule(action(2176), selectOnly + " and selectionmode='SOLID'", QtxPopupMgr::ToggleRule);
1187 mgr->insert( action(2177), selectolnyId, -1); //Compound
1188 mgr->setRule(action(2177), selectOnly, QtxPopupMgr::VisibleRule);
1189 mgr->setRule(action(2177), selectOnly + " and selectionmode='COMPOUND'", QtxPopupMgr::ToggleRule);
1190 mgr->insert( separator(), selectolnyId, -1);
1191 mgr->insert( action(2178), selectolnyId, -1); //Clear selection filter
1192 mgr->setRule(action(2178), selectOnly, QtxPopupMgr::VisibleRule);
1193 mgr->setRule(action(2178), selectOnly + " and selectionmode='ALL'", QtxPopupMgr::ToggleRule);
1194 mgr->insert( action( 213 ), -1, -1 ); // display only
1195 mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), QtxPopupMgr::VisibleRule );
1196 mgr->insert( separator(), -1, -1 );
1198 mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1201 //=======================================================================
1202 // function : GeometryGUI::activateModule()
1203 // purpose : Called when GEOM module is activated
1204 //=======================================================================
1205 bool GeometryGUI::activateModule( SUIT_Study* study )
1207 if ( CORBA::is_nil( myComponentGeom ) )
1210 bool res = SalomeApp_Module::activateModule( study );
1215 setMenuShown( true );
1216 setToolShown( true );
1218 connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1219 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1221 // Reset actions accelerator keys
1222 //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1223 //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1224 action(111)->setEnabled( true ); // Import: CTRL + Key_I
1225 action(121)->setEnabled( true ); // Export: CTRL + Key_E
1226 action( 33)->setEnabled( true ); // Delete: Key_Delete
1227 action(901)->setEnabled( true ); // Rename: Key_F2
1229 GUIMap::Iterator it;
1230 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1231 it.value()->activate( application()->desktop() );
1233 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1235 SUIT_ViewManager* vm;
1236 ViewManagerList OCCViewManagers, VTKViewManagers;
1238 application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1239 QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
1240 while ( itOCC.hasNext() && (vm = itOCC.next()) )
1241 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1243 application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1244 QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
1245 while ( itVTK.hasNext() && (vm = itVTK.next()) )
1246 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1249 SALOME_ListIO selected;
1250 sm->selectedObjects( selected );
1251 sm->clearSelected();
1253 // disable OCC selectors
1254 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1255 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1256 while ( itOCCSel.hasNext() )
1257 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1258 sr->setEnabled(true);
1260 // disable VTK selectors
1261 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1262 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1263 while ( itVTKSel.hasNext() )
1264 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1265 sr->setEnabled(true);
1267 sm->setSelectedObjects( selected, true ); //NPAL 19674
1273 //=======================================================================
1274 // function : GeometryGUI::deactivateModule()
1275 // purpose : Called when GEOM module is deactivated
1276 //=======================================================================
1277 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1279 setMenuShown( false );
1280 setToolShown( false );
1282 disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1283 this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1285 EmitSignalCloseAllDialogs();
1287 GUIMap::Iterator it;
1288 for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1289 it.value()->deactivate();
1291 // Unset actions accelerator keys
1292 //action(111)->setAccel(QKeySequence()); // Import
1293 //action(121)->setAccel(QKeySequence()); // Export
1294 action(111)->setEnabled( false ); // Import: CTRL + Key_I
1295 action(121)->setEnabled( false ); // Export: CTRL + Key_E
1296 action( 33)->setEnabled( false ); // Delete: Key_Delete
1297 action(901)->setEnabled( false ); // Rename: Key_F2
1299 qDeleteAll(myOCCSelectors);
1300 myOCCSelectors.clear();
1301 getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1303 qDeleteAll(myVTKSelectors);
1304 myVTKSelectors.clear();
1305 getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1307 return SalomeApp_Module::deactivateModule( study );
1310 //=======================================================================
1311 // function : GeometryGUI::BuildPresentation()
1313 //=======================================================================
1314 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1316 //GEOM_Displayer().Display( io, false, win );
1319 //=======================================================================
1320 // function : onWindowActivated()
1321 // purpose : update menu items' status - disable non-OCC-viewer-compatible actions
1322 //=======================================================================
1323 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1328 const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1329 //const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1331 // disable non-OCC viewframe menu commands
1332 // action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1333 action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1334 action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1335 action( 606 )->setEnabled( ViewOCC ); // CloseContour
1336 action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1337 action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1338 // action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1340 action( 800 )->setEnabled( ViewOCC ); // Create Group
1341 action( 801 )->setEnabled( ViewOCC ); // Edit Group
1343 action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1346 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1348 mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
1349 mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea );
1352 void GeometryGUI::viewManagers( QStringList& lst ) const
1354 lst.append( OCCViewer_Viewer::Type() );
1357 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1359 if ( vm->getType() == OCCViewer_Viewer::Type() )
1361 qDebug( "connect" );
1362 connect( vm, SIGNAL( keyPress ( SUIT_ViewWindow*, QKeyEvent* ) ),
1363 this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1364 connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1365 this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1366 connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1367 this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1370 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1371 myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1373 // disable OCC selectors
1374 getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1375 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1376 while ( itOCCSel.hasNext() )
1377 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1378 sr->setEnabled(true);
1380 else if ( vm->getType() == SVTK_Viewer::Type() )
1382 LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1383 myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1385 // disable VTK selectors
1386 getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1387 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1388 while ( itVTKSel.hasNext() )
1389 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1390 sr->setEnabled(true);
1394 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1396 SUIT_ViewModel* viewer = vm->getViewModel();
1397 if ( vm->getType() == OCCViewer_Viewer::Type() )
1399 QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
1400 while ( itOCCSel.hasNext() )
1401 if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
1402 if ( sr->viewer() == viewer )
1404 delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
1408 if ( vm->getType() == SVTK_Viewer::Type() )
1410 QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
1411 while ( itVTKSel.hasNext() )
1412 if ( LightApp_VTKSelector* sr = itVTKSel.next() )
1413 if ( sr->viewer() == viewer )
1415 delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
1421 QString GeometryGUI::engineIOR() const
1423 if ( !CORBA::is_nil( GetGeomGen() ) )
1424 return QString( getApp()->orb()->object_to_string( GetGeomGen() ) );
1428 LightApp_Selection* GeometryGUI::createSelection() const
1430 return new GEOMGUI_Selection();
1433 void GeometryGUI::contextMenuPopup( const QString& client, QMenu* menu, QString& title )
1435 SalomeApp_Module::contextMenuPopup(client, menu, title);
1438 getApp()->selectionMgr()->selectedObjects(lst);
1439 if (lst.Extent() < 1)
1442 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1443 _PTR(Study) study = appStudy->studyDS();
1445 bool isImported = true;
1446 SALOME_ListIteratorOfListIO anIt (lst);
1447 for (; anIt.More() && isImported; anIt.Next()) {
1448 Handle(SALOME_InteractiveObject) io = anIt.Value();
1449 _PTR(SObject) aSObj = study->FindObjectID(io->getEntry());
1451 if (lst.Extent() == 1) {
1452 // Set context menu title
1453 if (client == "OCCViewer" || client == "VTKViewer")
1454 title = QString(aSObj->GetName().c_str());
1457 CORBA::Object_var anObj = GeometryGUI::ClientSObjectToObject(aSObj);
1458 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObj);
1459 if (CORBA::is_nil(aGeomObj) || aGeomObj->GetType() != GEOM_IMPORT)
1465 menu->addAction(action(5029)); // Reload imported shape
1469 void GeometryGUI::createPreferences()
1471 int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1473 int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1474 setPreferenceProperty( genGroup, "columns", 2 );
1476 int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1477 LightApp_Preferences::Selector,
1478 "Geometry", "display_mode" );
1480 addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1481 LightApp_Preferences::Color, "Geometry", "shading_color" );
1483 addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1484 LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1486 addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1487 LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1489 addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1490 LightApp_Preferences::Color, "Geometry", "line_color" );
1492 addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1493 LightApp_Preferences::Color, "Geometry", "point_color" );
1495 addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1496 LightApp_Preferences::Color, "Geometry", "isos_color" );
1498 int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1499 LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1501 int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId );
1502 setPreferenceProperty( VertexGroup, "columns", 2 );
1504 int typeOfMarker = addPreference( tr( "PREF_TYPE_OF_MARKER" ), VertexGroup,
1505 LightApp_Preferences::Selector, "Geometry", "type_of_marker" );
1507 int markerScale = addPreference( tr( "PREF_MARKER_SCALE" ), VertexGroup,
1508 LightApp_Preferences::DblSpin, "Geometry", "marker_scale" );
1510 // Set property for default display mode
1511 QStringList aModesList;
1512 aModesList.append( tr("MEN_WIREFRAME") );
1513 aModesList.append( tr("MEN_SHADING") );
1515 QList<QVariant> anIndexesList;
1516 anIndexesList.append(0);
1517 anIndexesList.append(1);
1519 setPreferenceProperty( dispmode, "strings", aModesList );
1520 setPreferenceProperty( dispmode, "indexes", anIndexesList );
1522 // Set property for step value for spinboxes
1523 setPreferenceProperty( step, "min", 1 );
1524 setPreferenceProperty( step, "max", 10000 );
1525 setPreferenceProperty( step, "precision", 3 );
1527 // Set property for type of vertex marker
1528 QStringList aTypeOfMarkerList;
1529 QList<QVariant> anTypeOfMarkerIndexesList;
1531 aTypeOfMarkerList.append( tr("TOM_PLUS") );
1532 anTypeOfMarkerIndexesList.append(Aspect_TOM_PLUS);
1534 aTypeOfMarkerList.append( tr("TOM_POINT") );
1535 anTypeOfMarkerIndexesList.append(Aspect_TOM_POINT);
1537 aTypeOfMarkerList.append( tr("TOM_STAR") );
1538 anTypeOfMarkerIndexesList.append(Aspect_TOM_STAR);
1540 aTypeOfMarkerList.append( tr("TOM_O") );
1541 anTypeOfMarkerIndexesList.append(Aspect_TOM_O);
1543 aTypeOfMarkerList.append( tr("TOM_X") );
1544 anTypeOfMarkerIndexesList.append(Aspect_TOM_X);
1546 aTypeOfMarkerList.append( tr("TOM_O_POINT") );
1547 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_POINT);
1549 aTypeOfMarkerList.append( tr("TOM_O_PLUS") );
1550 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_PLUS);
1552 aTypeOfMarkerList.append( tr("TOM_O_STAR") );
1553 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_STAR);
1555 aTypeOfMarkerList.append( tr("TOM_O_X") );
1556 anTypeOfMarkerIndexesList.append(Aspect_TOM_O_X);
1559 setPreferenceProperty( typeOfMarker, "strings", aTypeOfMarkerList );
1560 setPreferenceProperty( typeOfMarker, "indexes", anTypeOfMarkerIndexesList );
1562 // Set property for Vertex Marker scale
1563 setPreferenceProperty( markerScale, "min", 1. );
1564 setPreferenceProperty( markerScale, "max", 7. );
1565 setPreferenceProperty( markerScale, "precision", 0.01 );
1566 setPreferenceProperty( markerScale, "step", 0.5 );
1570 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1572 if (section == "Geometry") {
1573 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1574 if (param == QString("SettingsGeomStep")) {
1575 double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1576 EmitSignalDefaultStepValueChanged(spin_step);
1581 LightApp_Displayer* GeometryGUI::displayer()
1584 myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1588 void GeometryGUI::setLocalSelectionMode(const int mode)
1590 myLocalSelectionMode = mode;
1592 int GeometryGUI::getLocalSelectionMode() const
1594 return myLocalSelectionMode;
1597 const char gSeparator = '_'; // character used to separate parameter names
1598 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1601 * \brief Store visual parameters
1603 * This method is called just before the study document is saved.
1604 * Store visual parameters in AttributeParameter attribue(s)
1606 void GeometryGUI::storeVisualParameters (int savePoint)
1608 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1609 if (!appStudy || !appStudy->studyDS())
1611 _PTR(Study) studyDS = appStudy->studyDS();
1613 // componentName is used for encoding of entries when storing them in IParameters
1614 std::string componentName = myComponentGeom->ComponentDataType();
1615 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1616 //if (!aSComponent) return;
1619 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1620 componentName.c_str(),
1622 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1624 // viewers counters are used for storing view_numbers in IParameters
1625 int vtkViewers(0), occViewers(0);
1627 QList<SUIT_ViewManager*> lst;
1628 QList<SUIT_ViewManager*>::Iterator it;
1630 // main cycle to store parameters of displayed objects
1632 vtkViewers = occViewers = 0;
1633 getApp()->viewManagers(lst);
1634 for (it = lst.begin(); it != lst.end(); it++)
1636 SUIT_ViewManager* vman = *it;
1637 QString vType = vman->getType();
1639 // saving VTK actors properties
1640 if (vType == SVTK_Viewer::Type())
1642 QVector<SUIT_ViewWindow*> views = vman->getViews();
1643 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1645 if (SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>(views[i]))
1647 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1648 allActors->InitTraversal();
1649 while (vtkActor* actor = allActors->GetNextActor())
1651 if (actor->GetVisibility()) // store only visible actors
1653 GEOM_Actor* aGeomActor = 0;
1654 if (actor->IsA("GEOM_Actor"))
1655 aGeomActor = GEOM_Actor::SafeDownCast(actor);
1656 if (aGeomActor && aGeomActor->hasIO())
1658 Handle(SALOME_InteractiveObject) io = aGeomActor->getIO();
1661 // entry is "encoded" = it does NOT contain component adress, since it is a
1662 // subject to change on next component loading
1663 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1665 std::string param, occParam = vType.toLatin1().data();
1666 occParam += gSeparator;
1667 occParam += QString::number(vtkViewers).toLatin1().data();
1668 occParam += gSeparator;
1670 param = occParam + "Visibility";
1671 ip->setParameter(entry, param, "On");
1673 param = occParam + "DisplayMode";
1674 ip->setParameter(entry, param, QString::number
1675 (aGeomActor->getDisplayMode()).toLatin1().data());
1677 vtkFloatingPointType r, g, b;
1678 aGeomActor->GetColor(r, g, b);
1679 QString colorStr = QString::number(r);
1680 colorStr += gDigitsSep; colorStr += QString::number(g);
1681 colorStr += gDigitsSep; colorStr += QString::number(b);
1682 param = occParam + "Color";
1683 ip->setParameter(entry, param, colorStr.toLatin1().data());
1685 param = occParam + "Opacity";
1686 ip->setParameter(entry, param, QString::number(aGeomActor->GetOpacity()).toLatin1().data());
1688 int nbUIso(0), nbVIso(0);
1689 aGeomActor->GetNbIsos(nbUIso,nbVIso);
1690 QString isosStr = QString::number(nbUIso);
1691 isosStr += gDigitsSep;
1692 isosStr += QString::number(nbVIso);
1693 param = occParam + "Isos";
1694 ip->setParameter(entry, param, isosStr.toLatin1().data());
1695 } // if (io->hasEntry())
1696 } // GEOM_Actor && hasIO
1698 } // while.. actors traversal
1702 } // if (SVTK view model)
1703 else if (vType == SOCC_Viewer::Type()) // processing OCC viewers
1705 QVector<SUIT_ViewWindow*> views = vman->getViews();
1706 for (int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++)
1708 SOCC_ViewWindow* occView = dynamic_cast<SOCC_ViewWindow*>(views[i]);
1711 //Handle(AIS_InteractiveContext) ic =
1712 // ((OCCViewer_Viewer*)(occView->getViewManager()->getViewModel()))->getAISContext();
1713 OCCViewer_Viewer* viewModel = (OCCViewer_Viewer*)(vman->getViewModel());
1714 //OCCViewer_Viewer* viewModel = ((OCCViewer_ViewManager*)vman)->getOCCViewer();
1715 Handle(AIS_InteractiveContext) ic = viewModel->getAISContext();
1717 AIS_ListOfInteractive aList;
1718 ic->DisplayedObjects(aList);
1720 AIS_ListIteratorOfListOfInteractive ite (aList);
1721 for (; ite.More(); ite.Next())
1723 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
1725 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1728 Handle(SALOME_InteractiveObject) io =
1729 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1732 // entry is "encoded": it does NOT contain component adress,
1733 // since it is a subject to change on next component loading
1734 std::string entry = ip->encodeEntry(io->getEntry(), componentName);
1736 std::string param, occParam = vType.toLatin1().data();
1737 occParam += gSeparator;
1738 occParam += QString::number(occViewers).toLatin1().data();
1739 occParam += gSeparator;
1742 param = occParam + "Visibility";
1743 ip->setParameter(entry, param, "On");
1746 param = occParam + "DisplayMode";
1747 int dm = aSh->DisplayMode();
1748 ip->setParameter(entry, param, QString::number(dm).toLatin1().data());
1751 // is a property of GEOM_Object, it is stored by GEOM engine
1754 param = occParam + "Transparency";
1755 ip->setParameter(entry, param, QString::number(aSh->Transparency()).toLatin1().data());
1758 Handle(AIS_Drawer) aDrawer = aSh->Attributes();
1759 int nbUIso = aDrawer->UIsoAspect()->Number();
1760 int nbVIso = aDrawer->VIsoAspect()->Number();
1761 QString isosStr = QString::number(nbUIso);
1762 isosStr += gDigitsSep;
1763 isosStr += QString::number(nbVIso);
1764 param = occParam + "Isos";
1765 ip->setParameter(entry, param, isosStr.toLatin1().data());
1766 } // if (io->hasEntry())
1768 } // if (GEOM_AISShape)
1769 } // for (AIS_ListOfInteractive)
1773 } // if (SOCC view model)
1776 // unknown viewer type
1778 } // for (viewManagers)
1782 * \brief Restore visual parameters
1784 * This method is called after the study document is opened.
1785 * Restore visual parameters from AttributeParameter attribue(s)
1787 void GeometryGUI::restoreVisualParameters (int savePoint)
1789 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(application()->activeStudy());
1790 if (!appStudy || !appStudy->studyDS())
1792 _PTR(Study) studyDS = appStudy->studyDS();
1794 // componentName is used for encoding of entries when storing them in IParameters
1795 std::string componentName = myComponentGeom->ComponentDataType();
1796 //_PTR(SComponent) aSComponent = studyDS->FindComponent("GEOM");
1797 //if (!aSComponent) return;
1800 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative",
1801 componentName.c_str(),
1803 _PTR(IParameters) ip = ClientFactory::getIParameters(ap);
1805 std::vector<std::string> entries = ip->getEntries();
1807 for (std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt)
1809 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1810 QString entry (ip->decodeEntry(*entIt).c_str());
1812 // Check that the entry corresponds to a real object in the Study
1813 // as the object may be deleted or modified after the visual state is saved.
1814 _PTR(SObject) so = studyDS->FindObjectID(entry.toLatin1().data());
1815 if (!so) continue; //Skip the not existent entry
1817 std::vector<std::string> paramNames = ip->getAllParameterNames( *entIt );
1818 std::vector<std::string> paramValues = ip->getAllParameterValues( *entIt );
1820 std::vector<std::string>::iterator namesIt = paramNames.begin();
1821 std::vector<std::string>::iterator valuesIt = paramValues.begin();
1823 // actors are stored in a map after displaying of them for
1824 // quicker access in the future: map < viewID to actor >
1825 NCollection_DataMap<int, GEOM_Actor* > vtkActors;
1826 NCollection_DataMap<int, Handle(GEOM_AISShape)> occActors;
1828 for (; namesIt != paramNames.end(); ++namesIt, ++valuesIt)
1830 // visual parameters are stored in strings as follows: ViewerType_ViewIndex_ParamName.
1831 // '_' is used as separator and should not be used in viewer type or parameter names.
1832 QStringList lst = QString((*namesIt).c_str()).split(gSeparator, QString::SkipEmptyParts);
1833 if (lst.size() != 3)
1836 QString viewerTypStr = lst[0];
1837 QString viewIndexStr = lst[1];
1838 QString paramNameStr = lst[2];
1841 int viewIndex = viewIndexStr.toUInt(&ok);
1842 if (!ok) // bad conversion of view index to integer
1846 if (viewerTypStr == SVTK_Viewer::Type())
1848 GEOM_Actor* vActor = 0;
1849 if (vtkActors.IsBound(viewIndex))
1850 vActor = vtkActors.Find(viewIndex);
1852 if (paramNameStr == "Visibility")
1854 if (!vActor && displayer())
1856 QList<SUIT_ViewManager*> lst;
1857 getApp()->viewManagers(viewerTypStr, lst);
1859 // SVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1860 if (viewIndex >= 0 && viewIndex < lst.count()) {
1861 SUIT_ViewManager* vman = lst.at(viewIndex);
1862 SUIT_ViewModel* vmodel = vman->getViewModel();
1863 // SVTK view model can be casted to SALOME_View
1864 displayer()->Display(entry, true, dynamic_cast<SALOME_View*>(vmodel));
1866 // store displayed actor in a temporary map for quicker
1867 // access later when restoring other parameters
1868 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1869 vtkRenderer* Renderer = vtkView->getRenderer();
1870 vtkActorCollection* theActors = Renderer->GetActors();
1871 theActors->InitTraversal();
1872 bool isFound = false;
1873 vtkActor *ac = theActors->GetNextActor();
1874 for (; ac != NULL && !isFound; ac = theActors->GetNextActor()) {
1875 if (ac->IsA("GEOM_Actor")) {
1876 GEOM_Actor* aGeomAc = GEOM_Actor::SafeDownCast(ac);
1877 if (aGeomAc->hasIO()) {
1878 Handle(SALOME_InteractiveObject) io =
1879 Handle(SALOME_InteractiveObject)::DownCast(aGeomAc->getIO());
1880 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1882 vtkActors.Bind(viewIndex, aGeomAc);
1889 } // if (paramNameStr == "Visibility")
1892 // the rest properties "work" with GEOM_Actor
1895 QString val ((*valuesIt).c_str());
1897 if (paramNameStr == "DisplayMode") {
1898 vActor->setDisplayMode(val.toInt());
1900 else if (paramNameStr == "Color") {
1901 QStringList colors = val.split(gDigitsSep, QString::SkipEmptyParts);
1902 if (colors.count() == 3)
1903 vActor->SetColor(colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat());
1905 else if (paramNameStr == "Opacity") {
1906 vActor->SetOpacity(val.toFloat());
1908 else if (paramNameStr == "Isos") {
1909 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1910 if (isos.count() == 2) {
1911 int aIsos[2] = {isos[0].toInt(), isos[1].toInt()};
1912 vActor->SetNbIsos(aIsos);
1916 } // other parameters than Visibility
1918 else if (viewerTypStr == SOCC_Viewer::Type())
1920 //Handle(AIS_InteractiveObject) occActor;
1921 Handle(GEOM_AISShape) occActor;
1922 if (occActors.IsBound(viewIndex))
1923 occActor = occActors.Find(viewIndex);
1925 // ViewModel and InteractiveContext
1926 SOCC_Viewer* occVModel = 0;
1927 Handle(AIS_InteractiveContext) ic;
1929 QList<SUIT_ViewManager*> lst;
1930 getApp()->viewManagers(viewerTypStr, lst);
1932 // SOCC ViewManager always has 1 ViewWindow, so view index is index of view manager
1933 if (viewIndex >= 0 && viewIndex < lst.count()) {
1934 SUIT_ViewManager* vman = lst.at(viewIndex);
1935 SUIT_ViewModel* vmodel = vman->getViewModel();
1936 occVModel = dynamic_cast<SOCC_Viewer*>(vmodel);
1938 ic = occVModel->getAISContext();
1944 if (paramNameStr == "Visibility")
1946 if (occActor.IsNull() && displayer())
1948 displayer()->Display(entry, true, occVModel);
1950 // store displayed actor in a temporary map for quicker
1951 // access later when restoring other parameters
1952 AIS_ListOfInteractive aList;
1953 ic->DisplayedObjects(aList);
1954 bool isFound = false;
1955 AIS_ListIteratorOfListOfInteractive ite (aList);
1956 for (; ite.More() && !isFound; ite.Next()) {
1957 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1958 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1960 Handle(SALOME_InteractiveObject) io =
1961 Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
1962 if (io->hasEntry() && strcmp(io->getEntry(), entry.toLatin1().data()) == 0) {
1964 occActors.Bind(viewIndex, aSh);
1970 } // if (paramNameStr == "Visibility")
1973 // the rest properties "work" with GEOM_AISShape
1974 if (!occActor.IsNull())
1976 QString val ((*valuesIt).c_str());
1978 if (paramNameStr == "DisplayMode") {
1979 ic->SetDisplayMode(occActor, AIS_DisplayMode(val.toInt()), false);
1980 //ic->Redisplay(occActor, Standard_False, Standard_True);
1982 // Color is restored by the GEOM engine
1983 else if (paramNameStr == "Transparency") {
1984 ic->SetTransparency(occActor, val.toFloat(), false);
1985 ic->Redisplay(occActor, Standard_False, Standard_True);
1987 else if (paramNameStr == "Isos") {
1988 QStringList isos = val.split(gDigitsSep, QString::SkipEmptyParts);
1989 if (isos.count() == 2) {
1990 Handle(AIS_Drawer) aDrawer = occActor->Attributes();
1991 int nbUIso = isos[0].toInt();
1992 int nbVIso = isos[1].toInt();
1993 Handle(Prs3d_IsoAspect) uIsoAspect = aDrawer->UIsoAspect();
1994 Handle(Prs3d_IsoAspect) vIsoAspect = aDrawer->VIsoAspect();
1995 uIsoAspect->SetNumber(nbUIso);
1996 vIsoAspect->SetNumber(nbVIso);
1997 aDrawer->SetUIsoAspect(uIsoAspect);
1998 aDrawer->SetVIsoAspect(vIsoAspect);
1999 ic->SetLocalAttributes(occActor, aDrawer);
2000 ic->Redisplay(occActor);
2004 } // other parameters than Visibility
2008 // unknown viewer type
2010 } // for names/parameters iterator
2011 } // for entries iterator
2013 // update all VTK and OCC views
2014 QList<SUIT_ViewManager*> lst;
2015 getApp()->viewManagers(lst);
2016 for (QList<SUIT_ViewManager*>::Iterator it = lst.begin(); it != lst.end(); it++) {
2017 SUIT_ViewModel* vmodel = (*it)->getViewModel();
2020 if (vmodel->getType() == SVTK_Viewer::Type()) {
2021 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) (*it)->getActiveView();
2022 vtkView->getRenderer()->ResetCameraClippingRange();
2025 else if (vmodel->getType() == SOCC_Viewer::Type()) {
2026 //SOCC_ViewWindow* occView = (SOCC_ViewWindow*) (*it)->getActiveView();
2027 SALOME_View* occVMod = dynamic_cast<SALOME_View*>(vmodel);