1 // VISU VISUGUI : GUI of VISU 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Module.cxx
25 // Author : Laurent CORNABE
29 #include "VisuGUI_Module.h"
31 #include "QtxPopupMgr.h"
33 #include "SUIT_Study.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ResourceMgr.h"
36 #include "SUIT_Accel.h"
37 #include "SUIT_Session.h"
39 #include "CAM_Module.h"
41 #include "SALOME_Event.hxx"
42 #include "SalomeApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_VTKSelector.h"
45 #include "LightApp_Preferences.h"
46 #include "LightApp_Displayer.h"
48 #include "SALOMEDS_IParameters.hxx"
50 #include "VVTK_ViewManager.h"
51 #include "VVTK_ViewWindow.h"
52 #include "VVTK_ViewModel.h"
54 #include "SVTK_ViewModel.h"
55 #include "SVTK_ViewManager.h"
56 #include "SVTK_MainWindow.h"
57 #include "SVTK_RenderWindowInteractor.h"
58 #include "VISU_Event.h"
60 #include "VisuGUI_Prs3dTools.h"
62 #include "VISU_GaussPoints_i.hh"
63 #include "VISU_GaussPtsAct.h"
64 #include "VisuGUI_GaussPointsDlg.h"
66 #include "VISU_Gen_i.hh"
67 #include "VISU_Result_i.hh"
68 #include "VISU_CutLines_i.hh"
70 #include "VISU_Actor.h"
71 #include "VISU_ScalarMapAct.h"
72 #include "VisuGUI_Tools.h"
73 #include "VisuGUI_ActionsDef.h"
75 #include "VISU_WidgetCtrl.hxx"
76 #include "VISU_PlanesWidget.hxx"
77 #include "VISU_SphereWidget.hxx"
79 #include "SalomeApp_Study.h"
80 #include "VVTK_MainWindow.h"
81 #include "VISU_View_i.hh"
85 #include <vtkRenderer.h>
86 #include <vtkCamera.h>
87 #include <vtkTimerLog.h>
93 static int MYDEBUG = 0;
95 static int MYDEBUG = 0;
98 #define GAUSS_NEW_VIEWER 5100
99 #define GAUSS_CREATE_PRS 5200
100 #define GAUSS_RENAME 5210
101 #define GAUSS_EDIT_PRS 5300
102 #define GAUSS_COPY_PRS 5310
103 #define GAUSS_ERASE_PRS 5400
104 #define GAUSS_DISPLAY_PRS 5500
105 #define GAUSS_DISPLAY_ONLY_PRS 5600
107 #define GAUSS_SAVE_CONFIGURATION 5700
108 #define GAUSS_OVERWRITE_CONFIGURATION 5701
109 #define GAUSS_RESTORE_CONFIGURATION 5702
110 #define GAUSS_RENAME_CONFIGURATION 5703
113 CreateCurves( SalomeApp_Module* theModule,
114 VISU::CutLines_i* thePrs,
116 const bool theCreate = true );
118 using namespace VISU;
122 //---------------------------------------------------------------
125 VVTK_ViewManager* myViewManager;
126 LightApp_VTKSelector* mySelector;
129 Viewer(VisuGUI_Module* theModule, TViewerMap& theViewerMap)
131 SalomeApp_Application* anApp = theModule->getApp();
132 myViewManager = new VVTK_ViewManager( anApp->activeStudy(), anApp->desktop() );
133 VVTK_Viewer* aViewer = (VVTK_Viewer*)myViewManager->getViewModel();
134 mySelector = new LightApp_VTKSelector( aViewer, anApp->selectionMgr() );
135 anApp->addViewManager( myViewManager );
137 theViewerMap.insert(TViewerMap::value_type(myViewManager,PViewer(this)));
138 QObject::connect( myViewManager, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
139 theModule, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
141 //aViewer->setBackgroundColor( Qt::darkGreen );
142 myViewManager->createViewWindow();
145 VVTK_ViewManager* getViewManager()
147 return myViewManager;
157 //---------------------------------------------------------------
158 typedef void (SUIT_ViewWindow::* TViewVisibility)();
160 SetViewVisibility(const TViewerMap& theViewerMap,
161 TViewVisibility theViewVisibility)
163 TViewerMap::const_iterator anIter = theViewerMap.begin();
164 for(; anIter != theViewerMap.end(); anIter++){
165 if(SUIT_ViewManager* aViewManager = anIter->first){
166 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
167 int aSize = aViews.size();
168 for(int anId = 0; anId < aSize; anId++){
169 if(SUIT_ViewWindow* aView = aViews[anId]){
170 (aView->* theViewVisibility)();
179 //---------------------------------------------------------------
187 //---------------------------------------------------------------
194 //---------------------------------------------------------------
197 initialize( CAM_Application* theApp )
199 VisuGUI::initialize( theApp );
201 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
204 aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_GAUSS_NEW_VIEWER"));
205 createAction( GAUSS_NEW_VIEWER,
206 tr("MEN_GAUSS_NEW_VIEWER"),
208 tr("MEN_GAUSS_NEW_VIEWER"),
209 tr("MEN_GAUSS_NEW_VIEWER"),
214 SLOT(onCreateViewManager()));
215 int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, 100 );
216 int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 );
217 createMenu( action( GAUSS_NEW_VIEWER ), newWinMenu, -1 );
219 // Add actions to menus
220 createMenu( tr( "MEN_GAUSS" ), -1, -1, 30 );
221 //createMenu( GAUSS_CREATE_PRS, aMenuId, 10 );
223 QString aViewerType = VVTK_Viewer::Type();
224 SUIT_Accel* accel = getApp()->accel();
225 accel->setActionKey( SUIT_Accel::PanLeft, Key_Left, aViewerType );
226 accel->setActionKey( SUIT_Accel::PanRight, Key_Right, aViewerType );
227 accel->setActionKey( SUIT_Accel::PanUp, Key_Up, aViewerType );
228 accel->setActionKey( SUIT_Accel::PanDown, Key_Down, aViewerType );
229 accel->setActionKey( SUIT_Accel::ZoomIn, Key_PageUp, aViewerType );
230 accel->setActionKey( SUIT_Accel::ZoomOut, Key_PageDown, aViewerType );
231 accel->setActionKey( SUIT_Accel::RotateLeft, CTRL+Key_Left, aViewerType );
232 accel->setActionKey( SUIT_Accel::RotateRight, CTRL+Key_Right, aViewerType );
233 accel->setActionKey( SUIT_Accel::RotateUp, CTRL+Key_Up, aViewerType );
234 accel->setActionKey( SUIT_Accel::RotateDown, CTRL+Key_Down, aViewerType );
235 accel->setActionKey( SVTK::PlusSpeedIncrementEvent, Key_Plus, aViewerType );
236 accel->setActionKey( SVTK::MinusSpeedIncrementEvent, Key_Minus, aViewerType );
238 connect( getApp(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ),
239 this, SLOT( OnViewManagerAdded (SUIT_ViewManager*) ) );
241 // Prepare popup menus
242 QtxPopupMgr* mgr = popupMgr();
245 aPixmap = aResourceMgr->loadPixmap( "VISU", tr( "ICON_GAUSS_POINTS" ) );
246 createAction( GAUSS_CREATE_PRS, tr("MEN_GAUSS_CREATE_PRS"), aPixmap,
247 tr("MEN_GAUSS_CREATE_PRS"), "", 0, this, false,
248 this, SLOT(OnCreateGaussPoints()));
249 mgr->insert( action( GAUSS_CREATE_PRS ), -1, 0, -1 );
250 mgr->setRule( action( GAUSS_CREATE_PRS ),
251 "client='ObjectBrowser' and selcount=1 "
252 "and type='VISU::TTIMESTAMP' "
253 "and $medEntity in {'EDGE_ENTITY' 'FACE_ENTITY' 'CELL_ENTITY'} "
254 "and $medSource in {'eImportFile' 'eCopyAndImportFile'} ",
257 createMenu( action( GAUSS_CREATE_PRS ), createMenu( tr( "MEN_VISUALISATION" ), -1 ), -1 );
258 createTool( GAUSS_CREATE_PRS, createTool( tr( "TOOL_VISUALISATION" ) ), -1 );
260 createAction( GAUSS_RENAME, VisuGUI::tr("MEN_RENAME"), QIconSet(),
261 VisuGUI::tr("MEN_RENAME"), "", 0, this, false,
262 this, SLOT(OnRename()));
263 mgr->insert( action( GAUSS_RENAME ), -1, 0, -1 );
264 mgr->setRule( action( GAUSS_RENAME ),
265 "selcount=1 and type='VISU::TGAUSSPOINTS'",
268 createAction( GAUSS_EDIT_PRS, VisuGUI::tr("MEN_EDIT_PRS"), QIconSet(),
269 VisuGUI::tr("MEN_EDIT_PRS"), "", 0, this, false,
270 this, SLOT(OnEditGaussPoints()));
271 mgr->insert( action( GAUSS_EDIT_PRS ), -1, 0, -1 );
272 mgr->setRule( action( GAUSS_EDIT_PRS ),
273 "selcount=1 and type='VISU::TGAUSSPOINTS'",
276 createAction( GAUSS_COPY_PRS, VisuGUI::tr("MEN_COPY_PRS"), QIconSet(),
277 VisuGUI::tr("MEN_COPY_PRS"), "", 0, this, false,
278 this, SLOT(OnCopyPresentation()));
279 mgr->insert( action( GAUSS_COPY_PRS ), -1, 0, -1 );
280 mgr->setRule( action( GAUSS_COPY_PRS ),
281 "selcount=1 and type='VISU::TGAUSSPOINTS'",
283 action( GAUSS_COPY_PRS )->setEnabled(false);
285 aRule = "(selcount>0 and type='VISU::TGAUSSPOINTS')";
287 createAction( GAUSS_ERASE_PRS, VisuGUI::tr("MEN_ERASE"), QIconSet(),
288 VisuGUI::tr("MEN_ERASE"), "", 0, this, false,
289 this, SLOT(OnErasePrs()));
290 mgr->insert( action( GAUSS_ERASE_PRS ), -1, -1, -1 ); // erase
291 mgr->setRule( action( GAUSS_ERASE_PRS ),
292 aRule + " and ({true} in $canBeDisplayed) and (isVisible=true)", true );
294 createAction( GAUSS_DISPLAY_PRS, VisuGUI::tr("MEN_DISPLAY"), QIconSet(),
295 VisuGUI::tr("MEN_DISPLAY"), "", 0, this, false,
296 this, SLOT(OnDisplayPrs()));
297 mgr->insert( action( GAUSS_DISPLAY_PRS ), -1, -1, -1 ); // display
298 mgr->setRule( action( GAUSS_DISPLAY_PRS ),
299 aRule + " and ({true} in $canBeDisplayed) and (isVisible=false)", true );
301 createAction( GAUSS_DISPLAY_ONLY_PRS, VisuGUI::tr("MEN_DISPLAY_ONLY"), QIconSet(),
302 VisuGUI::tr("MEN_DISPLAY_ONLY"), "", 0, this, false,
303 this, SLOT(OnDisplayOnlyPrs()));
304 mgr->insert( action( GAUSS_DISPLAY_ONLY_PRS ), -1, -1, -1 ); // display only
305 mgr->setRule( action( GAUSS_DISPLAY_ONLY_PRS ),
306 aRule + " and ({true} in $canBeDisplayed)", true );
308 createAction( GAUSS_RENAME_CONFIGURATION, VisuGUI::tr("MEN_RENAME"), QIconSet(),
309 VisuGUI::tr("MEN_RENAME"), "", 0, this, false,
310 this, SLOT(OnRename()));
311 mgr->insert( action( GAUSS_RENAME_CONFIGURATION ), -1, -1, -1 );
312 mgr->setRule( action( GAUSS_RENAME_CONFIGURATION ), "selcount=1 and type='VISU::TGAUSSVIEW'", true );
314 createAction( GAUSS_SAVE_CONFIGURATION, tr("MEN_SAVE_CONFIGURATION"), QIconSet(),
315 tr("MEN_SAVE_CONFIGURATION"), "", 0, this, false,
316 this, SLOT(OnSaveConfiguration()));
317 mgr->insert( action( GAUSS_SAVE_CONFIGURATION ), -1, -1, -1 );
318 mgr->setRule( action( GAUSS_SAVE_CONFIGURATION ),
319 "selcount>=0 and client='VVTK' and activeView='VVTK'", true );
321 createAction( GAUSS_OVERWRITE_CONFIGURATION, tr("MEN_OVERWRITE_CONFIGURATION"), QIconSet(),
322 tr("MEN_OVERWRITE_CONFIGURATION"), "", 0, this, false,
323 this, SLOT(OnOverwriteConfiguration()));
324 mgr->insert( action( GAUSS_OVERWRITE_CONFIGURATION ), -1, -1, -1 );
325 mgr->setRule( action( GAUSS_OVERWRITE_CONFIGURATION ),
326 "selcount>0 and type='VISU::TGAUSSVIEW' and activeView='VVTK'", true );
328 createAction( GAUSS_RESTORE_CONFIGURATION, tr("MEN_RESTORE_CONFIGURATION"), QIconSet(),
329 tr("MEN_RESTORE_CONFIGURATION"), "", 0, this, false,
330 this, SLOT(OnRestoreConfiguration()));
331 mgr->insert( action( GAUSS_RESTORE_CONFIGURATION ), -1, -1, -1 );
332 mgr->setRule( action( GAUSS_RESTORE_CONFIGURATION ),
333 "selcount=1 and type='VISU::TGAUSSVIEW'", true );
336 //---------------------------------------------------------------
339 activateModule( SUIT_Study* theStudy )
341 VisuGUI::activateModule( theStudy );
343 SetViewVisibility(myViewerMap,&SUIT_ViewWindow::show);
349 //---------------------------------------------------------------
352 deactivateModule( SUIT_Study* theStudy )
354 VisuGUI::deactivateModule( theStudy );
356 SetViewVisibility(myViewerMap,&SUIT_ViewWindow::hide);
362 //---------------------------------------------------------------
365 onCreateViewManager()
367 Viewer* aViewer = new Viewer( this, myViewerMap );
368 return aViewer->getViewManager();
372 //---------------------------------------------------------------
375 onLastViewClosed(SUIT_ViewManager* theViewManager)
377 myViewerMap.erase(theViewManager);
381 //---------------------------------------------------------------
386 VisuGUI::createPreferences();
388 createGaussPointsPreferences();
389 createInsideCursorPreferences();
390 createOutsideCursorPreferences();
391 createPickingPreferences();
392 createSpaceMousePreferences();
393 createRecorderPreferences();
397 //---------------------------------------------------------------
400 createGaussPointsPreferences()
402 int gaussTab = addPreference( tr( "VISU_GAUSS_PREF_TAB_TTL" ) );
403 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), gaussTab );
404 setPreferenceProperty( primitiveGr, "columns", 1 );
406 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
407 LightApp_Preferences::Selector, "VISU",
408 "point_sprite_primitive_type" );
411 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
412 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
413 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
414 QValueList<QVariant> indices;
418 setPreferenceProperty( primitiveTypePref, "strings", values );
419 setPreferenceProperty( primitiveTypePref, "indexes", indices );
421 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
422 LightApp_Preferences::IntSpin, "VISU", "point_sprite_clamp" );
423 setPreferenceProperty( clampPref, "min", 1 );
424 setPreferenceProperty( clampPref, "max", 512 );
426 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
427 LightApp_Preferences::File, "VISU", "point_sprite_main_texture" );
429 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
430 LightApp_Preferences::File, "VISU", "point_sprite_alpha_texture" );
432 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
433 LightApp_Preferences::DblSpin, "VISU",
434 "point_sprite_alpha_threshold" );
435 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
436 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
437 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
439 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
440 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_resolution" );
441 setPreferenceProperty( resolutionPref, "min", 3 );
442 setPreferenceProperty( resolutionPref, "max", 100 );
444 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
445 LightApp_Preferences::IntSpin, "VISU", "geom_sphere_face_limit" );
446 setPreferenceProperty( faceLimitPref, "min", 10 );
447 setPreferenceProperty( faceLimitPref, "max", 1000000 );
449 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), gaussTab );
450 setPreferenceProperty( sizeGr, "columns", 2 );
452 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
453 LightApp_Preferences::IntSpin, "VISU", "point_sprite_min_size" );
454 setPreferenceProperty( minSizePref, "min", 1 );
455 setPreferenceProperty( minSizePref, "max", 100 );
457 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
458 LightApp_Preferences::IntSpin, "VISU", "point_sprite_max_size" );
459 setPreferenceProperty( maxSizePref, "min", 1 );
460 setPreferenceProperty( maxSizePref, "max", 100 );
462 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), sizeGr,
463 LightApp_Preferences::IntSpin, "VISU",
464 "point_sprite_magnification" );
465 setPreferenceProperty( magnificationPref, "min", 10 );
466 setPreferenceProperty( magnificationPref, "max", 1000 );
468 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), sizeGr,
469 LightApp_Preferences::DblSpin, "VISU", "point_sprite_increment" );
470 setPreferenceProperty( incrementPref, "min", 0.01 );
471 setPreferenceProperty( incrementPref, "max", 10 );
472 setPreferenceProperty( incrementPref, "step", 0.1 );
474 int geomGr = addPreference( tr( "VISU_GAUSS_PREF_GEOM_GROUP_TTL" ), gaussTab );
475 setPreferenceProperty( geomGr, "columns", 1 );
477 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), geomGr,
478 LightApp_Preferences::IntSpin, "VISU", "point_sprite_size" );
479 setPreferenceProperty( sizePref, "min", 1 );
480 setPreferenceProperty( sizePref, "max", 100 );
482 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), geomGr,
483 LightApp_Preferences::Color, "VISU", "point_sprite_color" );
485 // ScalarBar Preferences
486 int scalarBarGr = addPreference( tr( "VISU_GAUSS_SCALAR_BAR_PREF_GROUP_TTL" ), gaussTab );
487 setPreferenceProperty( scalarBarGr, "columns", 1 );
489 int activeBarPref = addPreference( tr( "VISU_GAUSS_PREF_ACTIVE_BAR" ), scalarBarGr,
490 LightApp_Preferences::Selector, "VISU", "scalar_bar_active_local" );
493 values.append( tr( "VISU_GAUSS_PREF_LOCAL" ) );
494 values.append( tr( "VISU_GAUSS_PREF_GLOBAL" ) );
498 setPreferenceProperty( activeBarPref, "strings", values );
499 setPreferenceProperty( activeBarPref, "indexes", indices );
501 addPreference( tr( "VISU_GAUSS_PREF_DISPLAY_GLOBAL" ), scalarBarGr,
502 LightApp_Preferences::Bool, "VISU", "scalar_bar_display_global" );
504 int colorPref = addPreference( tr( "VISU_GAUSS_PREF_SCALAR_BAR_MODE" ), scalarBarGr,
505 LightApp_Preferences::Selector, "VISU", "scalar_bar_bicolor" );
508 values.append( tr( "VISU_GAUSS_PREF_BICOLOR" ) );
509 values.append( tr( "VISU_GAUSS_PREF_RAINBOW" ) );
513 setPreferenceProperty( colorPref, "strings", values );
514 setPreferenceProperty( colorPref, "indexes", indices );
516 int spacingPref = addPreference( tr( "VISU_GAUSS_PREF_SPACING" ), scalarBarGr,
517 LightApp_Preferences::DblSpin, "VISU", "scalar_bar_spacing" );
518 setPreferenceProperty( spacingPref, "min", 0.01 );
519 setPreferenceProperty( spacingPref, "max", 1.0 );
520 setPreferenceProperty( spacingPref, "step", 0.01 );
524 //---------------------------------------------------------------
527 createInsideCursorPreferences()
529 int insideCursorTab = addPreference( tr( "VISU_GAUSS_INSIDE_CURSOR_PREF_TAB_TTL" ) );
531 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), insideCursorTab );
532 setPreferenceProperty( primitiveGr, "columns", 1 );
534 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
535 LightApp_Preferences::Selector, "VISU",
536 "inside_point_sprite_primitive_type" );
539 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
540 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
541 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
542 QValueList<QVariant> indices;
546 setPreferenceProperty( primitiveTypePref, "strings", values );
547 setPreferenceProperty( primitiveTypePref, "indexes", indices );
549 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
550 LightApp_Preferences::IntSpin, "VISU", "inside_point_sprite_clamp" );
551 setPreferenceProperty( clampPref, "min", 1 );
552 setPreferenceProperty( clampPref, "max", 512 );
554 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
555 LightApp_Preferences::File, "VISU", "inside_point_sprite_main_texture" );
557 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
558 LightApp_Preferences::File, "VISU", "inside_point_sprite_alpha_texture" );
560 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
561 LightApp_Preferences::DblSpin, "VISU",
562 "inside_point_sprite_alpha_threshold" );
563 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
564 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
565 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
567 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
568 LightApp_Preferences::IntSpin, "VISU",
569 "inside_geom_sphere_resolution" );
570 setPreferenceProperty( resolutionPref, "min", 3 );
571 setPreferenceProperty( resolutionPref, "max", 100 );
573 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
574 LightApp_Preferences::IntSpin, "VISU",
575 "inside_geom_sphere_face_limit" );
576 setPreferenceProperty( faceLimitPref, "min", 10 );
577 setPreferenceProperty( faceLimitPref, "max", 1000000 );
579 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), insideCursorTab );
580 setPreferenceProperty( sizeGr, "columns", 2 );
582 int minSizePref = addPreference( tr( "VISU_GAUSS_PREF_MIN_SIZE" ), sizeGr,
583 LightApp_Preferences::IntSpin, "VISU",
584 "inside_point_sprite_min_size" );
585 setPreferenceProperty( minSizePref, "min", 1 );
586 setPreferenceProperty( minSizePref, "max", 100 );
588 int maxSizePref = addPreference( tr( "VISU_GAUSS_PREF_MAX_SIZE" ), sizeGr,
589 LightApp_Preferences::IntSpin, "VISU",
590 "inside_point_sprite_max_size" );
591 setPreferenceProperty( maxSizePref, "min", 1 );
592 setPreferenceProperty( maxSizePref, "max", 100 );
594 int magnificationGr = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION_GROUP_TTL" ), insideCursorTab );
595 setPreferenceProperty( magnificationGr, "columns", 2 );
597 int magnificationPref = addPreference( tr( "VISU_GAUSS_PREF_MAGNIFICATION" ), magnificationGr,
598 LightApp_Preferences::IntSpin, "VISU",
599 "inside_point_sprite_magnification" );
600 setPreferenceProperty( magnificationPref, "min", 10 );
601 setPreferenceProperty( magnificationPref, "max", 1000 );
603 int incrementPref = addPreference( tr( "VISU_GAUSS_PREF_INCREMENT" ), magnificationGr,
604 LightApp_Preferences::DblSpin, "VISU",
605 "inside_point_sprite_increment" );
606 setPreferenceProperty( incrementPref, "min", 0.01 );
607 setPreferenceProperty( incrementPref, "max", 10 );
608 setPreferenceProperty( incrementPref, "step", 0.1 );
612 //---------------------------------------------------------------
615 createOutsideCursorPreferences()
617 int outsideCursorTab = addPreference( tr( "VISU_GAUSS_OUTSIDE_CURSOR_PREF_TAB_TTL" ) );
619 int primitiveGr = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_GROUP_TTL" ), outsideCursorTab );
620 setPreferenceProperty( primitiveGr, "columns", 1 );
622 int primitiveTypePref = addPreference( tr( "VISU_GAUSS_PREF_PRIMITIVE_TYPE" ), primitiveGr,
623 LightApp_Preferences::Selector, "VISU",
624 "outside_point_sprite_primitive_type" );
627 values.append( tr( "VISU_GAUSS_PREF_POINTSPRITE" ) );
628 values.append( tr( "VISU_GAUSS_PREF_OPENGLPOINT" ) );
629 values.append( tr( "VISU_GAUSS_PREF_GEOMSPHERE" ) );
630 QValueList<QVariant> indices;
634 setPreferenceProperty( primitiveTypePref, "strings", values );
635 setPreferenceProperty( primitiveTypePref, "indexes", indices );
637 int clampPref = addPreference( tr( "VISU_GAUSS_PREF_CLAMP" ), primitiveGr,
638 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_clamp" );
639 setPreferenceProperty( clampPref, "min", 1 );
640 setPreferenceProperty( clampPref, "max", 512 );
642 addPreference( tr( "VISU_GAUSS_PREF_MAIN_TEXTURE" ), primitiveGr,
643 LightApp_Preferences::File, "VISU", "outside_point_sprite_main_texture" );
645 addPreference( tr( "VISU_GAUSS_PREF_ALPHA_TEXTURE" ), primitiveGr,
646 LightApp_Preferences::File, "VISU", "outside_point_sprite_alpha_texture" );
648 int alphaThresholdPref = addPreference( tr( "VISU_GAUSS_PREF_ALPHA_THRESHOLD" ), primitiveGr,
649 LightApp_Preferences::DblSpin, "VISU",
650 "outside_point_sprite_alpha_threshold" );
651 setPreferenceProperty( alphaThresholdPref, "min", 0.0 );
652 setPreferenceProperty( alphaThresholdPref, "max", 1.0 );
653 setPreferenceProperty( alphaThresholdPref, "step", 0.1 );
655 int resolutionPref = addPreference( tr( "VISU_GAUSS_PREF_RESOLUTION" ), primitiveGr,
656 LightApp_Preferences::IntSpin, "VISU",
657 "outside_geom_sphere_resolution" );
658 setPreferenceProperty( resolutionPref, "min", 3 );
659 setPreferenceProperty( resolutionPref, "max", 100 );
661 int faceLimitPref = addPreference( tr( "VISU_GAUSS_PREF_FACE_LIMIT" ), primitiveGr,
662 LightApp_Preferences::IntSpin, "VISU",
663 "outside_geom_sphere_face_limit" );
664 setPreferenceProperty( faceLimitPref, "min", 10 );
665 setPreferenceProperty( faceLimitPref, "max", 1000000 );
667 int sizeGr = addPreference( tr( "VISU_GAUSS_PREF_SIZE_GROUP_TTL" ), outsideCursorTab );
669 int sizePref = addPreference( tr( "VISU_GAUSS_PREF_SIZE" ), sizeGr,
670 LightApp_Preferences::IntSpin, "VISU", "outside_point_sprite_size" );
671 setPreferenceProperty( sizePref, "min", 1 );
672 setPreferenceProperty( sizePref, "max", 100 );
674 int colorGr = addPreference( tr( "VISU_GAUSS_PREF_COLOR_GROUP_TTL" ), outsideCursorTab );
675 setPreferenceProperty( colorGr, "columns", 1 );
677 addPreference( tr( "VISU_GAUSS_PREF_UNIFORM_COLOR" ), colorGr,
678 LightApp_Preferences::Bool, "VISU", "outside_point_sprite_uniform" );
680 addPreference( tr( "VISU_GAUSS_PREF_COLOR" ), colorGr,
681 LightApp_Preferences::Color, "VISU", "outside_point_sprite_color" );
685 //---------------------------------------------------------------
688 createPickingPreferences()
690 int pickingTab = addPreference( tr( "VISU_PICKING_PREF_TAB_TTL" ) );
693 int cursorGr = addPreference( tr( "VISU_PICKING_PREF_CURSOR_GROUP_TTL" ), pickingTab );
694 setPreferenceProperty( cursorGr, "columns", 1 );
696 int cursorSizePref = addPreference( tr( "VISU_PICKING_PREF_CURSOR_SIZE" ), cursorGr,
697 LightApp_Preferences::DblSpin, "VISU", "picking_cursor_size" );
698 setPreferenceProperty( cursorSizePref, "min", 0 );
699 setPreferenceProperty( cursorSizePref, "max", 1.0 );
700 setPreferenceProperty( cursorSizePref, "step", 0.1 );
702 int pyramidHeightPref = addPreference( tr( "VISU_PICKING_PREF_PYRAMID_HEIGHT" ), cursorGr,
703 LightApp_Preferences::DblSpin, "VISU", "picking_pyramid_height" );
704 setPreferenceProperty( pyramidHeightPref, "min", 1 );
705 setPreferenceProperty( pyramidHeightPref, "max", 100 );
707 /*int selectionColorPref = */
708 addPreference( tr( "VISU_PICKING_PREF_SELECTION_COLOR" ), cursorGr,
709 LightApp_Preferences::Color, "VISU", "picking_selection_color" );
712 int toleranceGr = addPreference( tr( "VISU_PICKING_PREF_TOLERANCE_GROUP_TTL" ), pickingTab );
714 int pointTolerancePref = addPreference( tr( "VISU_PICKING_PREF_POINT_SELECTION_TOLERANCE" ), toleranceGr,
715 LightApp_Preferences::DblSpin, "VISU", "picking_point_tolerance" );
716 setPreferenceProperty( pointTolerancePref, "min", 0.001 );
717 setPreferenceProperty( pointTolerancePref, "max", 10 );
718 setPreferenceProperty( pointTolerancePref, "step", 0.01 );
721 int infoWindowGr = addPreference( tr( "VISU_PICKING_PREF_INFO_WINDOW_GROUP_TTL" ), pickingTab );
722 setPreferenceProperty( infoWindowGr, "columns", 1 );
724 int transparencyPref = addPreference( tr( "VISU_PICKING_PREF_TRANSPARENCY" ), infoWindowGr,
725 LightApp_Preferences::IntSpin, "VISU", "picking_transparency" );
726 setPreferenceProperty( transparencyPref, "min", 0 );
727 setPreferenceProperty( transparencyPref, "max", 100 );
728 setPreferenceProperty( transparencyPref, "step", 10 );
730 int positionPref = addPreference( tr( "VISU_PICKING_PREF_POSITION" ), infoWindowGr,
731 LightApp_Preferences::Selector, "VISU", "picking_position" );
733 values.append( tr( "VISU_PICKING_PREF_BELOW_POINT" ) );
734 values.append( tr( "VISU_PICKING_PREF_TOP_LEFT_CORNER" ) );
735 QValueList<QVariant> indices;
738 setPreferenceProperty( positionPref, "strings", values );
739 setPreferenceProperty( positionPref, "indexes", indices );
742 int cameraGr = addPreference( tr( "VISU_PICKING_PREF_CAMERA_GROUP_TTL" ), pickingTab );
743 setPreferenceProperty( cameraGr, "columns", 1 );
745 int zoomFactorPref = addPreference( tr( "VISU_PICKING_PREF_ZOOM_FACTOR" ), cameraGr,
746 LightApp_Preferences::DblSpin, "VISU", "picking_zoom_factor" );
747 setPreferenceProperty( zoomFactorPref, "min", 0.1 );
748 setPreferenceProperty( zoomFactorPref, "max", 10.0 );
749 setPreferenceProperty( zoomFactorPref, "step", 0.1 );
751 int stepNumberPref = addPreference( tr( "VISU_PICKING_PREF_STEP_NUMBER" ), cameraGr,
752 LightApp_Preferences::IntSpin, "VISU", "picking_step_number" );
753 setPreferenceProperty( stepNumberPref, "min", 1 );
754 setPreferenceProperty( stepNumberPref, "max", 100 );
756 // Display parent mesh
757 int parentMeshGr = addPreference( tr( "VISU_PICKING_PREF_PARENT_MESH_TTL" ), pickingTab );
758 setPreferenceProperty( parentMeshGr, "columns", 1 );
760 addPreference( tr( "VISU_PICKING_PREF_DISPLAY_PARENT_MESH" ), parentMeshGr,
761 LightApp_Preferences::Bool, "VISU", "picking_display_parent_mesh" );
765 //---------------------------------------------------------------
768 createSpaceMousePreferences()
770 int mouseTab = addPreference( tr( "VISU_MOUSE_PREF_TAB_TLT" ) );
772 int mouseGr = addPreference( tr( "VISU_MOUSE_PREF_GROUP_TLT" ), mouseTab );
773 int mousePref = addPreference( tr( "VISU_MOUSE_PREF" ), mouseGr,
774 LightApp_Preferences::Selector, "VISU", "mouse_behaviour" );
776 values.append( tr( "VISU_MOUSE_PREF_STANDARD" ) );
777 values.append( tr( "VISU_MOUSE_PREF_KEYBOARD_FREE" ) );
778 QValueList<QVariant> indices;
781 setPreferenceProperty( mousePref, "strings", values );
782 setPreferenceProperty( mousePref, "indexes", indices );
784 int keybrdGr = addPreference( tr( "VISU_KEYBOARD_PREF_GROUP_TTL" ), mouseTab );
785 int keybrdPref = addPreference( tr( "VISU_KEYBOARD_PREF" ), keybrdGr,
786 LightApp_Preferences::IntSpin, "VISU", "speed_increment" );
787 setPreferenceProperty( keybrdPref, "max", 1000 );
789 int spacemouseGr = addPreference( tr( "VISU_SPACEMOUSE_PREF" ), mouseTab );
790 setPreferenceProperty( spacemouseGr, "columns", 1 );
791 int spacemousePref1 = addPreference( tr( "VISU_SPACEMOUSE_PREF_1" ), spacemouseGr,
792 LightApp_Preferences::Selector, "VISU",
793 "spacemouse_func1_btn" ); //decrease_speed_increment
794 int spacemousePref2 = addPreference( tr( "VISU_SPACEMOUSE_PREF_2" ), spacemouseGr,
795 LightApp_Preferences::Selector, "VISU",
796 "spacemouse_func2_btn" ); //increase_speed_increment
797 int spacemousePref3 = addPreference( tr( "VISU_SPACEMOUSE_PREF_3" ), spacemouseGr,
798 LightApp_Preferences::Selector, "VISU",
799 "spacemouse_func3_btn" ); //decrease_gauss_point_magnification
800 int spacemousePref4 = addPreference( tr( "VISU_SPACEMOUSE_PREF_4" ), spacemouseGr,
801 LightApp_Preferences::Selector, "VISU",
802 "spacemouse_func4_btn" ); //increase_gauss_point_magnification
803 int spacemousePref5 = addPreference( tr( "VISU_SPACEMOUSE_PREF_5" ), spacemouseGr,
804 LightApp_Preferences::Selector, "VISU",
805 "spacemouse_func5_btn" ); //dominant_combined_switch
807 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_1" ) );
808 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_2" ) );
809 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_3" ) );
810 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_4" ) );
811 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_5" ) );
812 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_6" ) );
813 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_7" ) );
814 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_8" ) );
815 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_*" ) );
816 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_10" ) );
817 values.append( tr( "VISU_SPACEMOUSE_PREF_BTN_11" ) );
827 indices.append( 9 ); // == button_*
828 indices.append( 10 );
829 indices.append( 11 );
830 setPreferenceProperty( spacemousePref1, "strings", values );
831 setPreferenceProperty( spacemousePref1, "indexes", indices );
832 setPreferenceProperty( spacemousePref2, "strings", values );
833 setPreferenceProperty( spacemousePref2, "indexes", indices );
834 setPreferenceProperty( spacemousePref3, "strings", values );
835 setPreferenceProperty( spacemousePref3, "indexes", indices );
836 setPreferenceProperty( spacemousePref4, "strings", values );
837 setPreferenceProperty( spacemousePref4, "indexes", indices );
838 setPreferenceProperty( spacemousePref5, "strings", values );
839 setPreferenceProperty( spacemousePref5, "indexes", indices );
843 //---------------------------------------------------------------
846 createRecorderPreferences()
848 int recorderTab = addPreference( tr( "VISU_RECORDER_PREF_TAB_TTL" ) );
850 int recorderGr = addPreference( tr( "VISU_RECORDER_PREF_GROUP_TTL" ), recorderTab );
851 setPreferenceProperty( recorderGr, "columns", 1 );
853 int modePref = addPreference( tr( "VISU_RECORDER_PREF_RECORDING_MODE" ), recorderGr,
854 LightApp_Preferences::Selector, "VISU", "recorder_mode" );
856 values.append( tr( "VISU_RECORDER_PREF_SKIPPED_FRAMES" ) );
857 values.append( tr( "VISU_RECORDER_PREF_ALL_DISLPAYED_FRAMES" ) );
858 QValueList<QVariant> indices;
861 setPreferenceProperty( modePref, "strings", values );
862 setPreferenceProperty( modePref, "indexes", indices );
864 int fpsPref = addPreference( tr( "VISU_RECORDER_PREF_FPS" ), recorderGr,
865 LightApp_Preferences::DblSpin, "VISU", "recorder_fps" );
866 setPreferenceProperty( fpsPref, "min", 0.1 );
867 setPreferenceProperty( fpsPref, "max", 100 );
869 int qualityPref = addPreference( tr( "VISU_RECORDER_PREF_QUALITY" ), recorderGr,
870 LightApp_Preferences::IntSpin, "VISU", "recorder_quality" );
871 setPreferenceProperty( qualityPref, "min", 1 );
872 setPreferenceProperty( qualityPref, "max", 100 );
874 addPreference( tr( "VISU_RECORDER_PREF_PROGRESSIVE" ), recorderGr,
875 LightApp_Preferences::Bool, "VISU", "recorder_progressive" );
879 //---------------------------------------------------------------
882 OnCreateGaussPoints()
884 double initialTime = vtkTimerLog::GetCPUTime();
885 CreatePrs3d<VISU::GaussPoints_i, VVTK_Viewer, VisuGUI_GaussPointsDlg, 1>(this);
886 INFOS( "VisuGUI_Module::OnCreateGaussPoints() : Gauss Points created in " <<
887 vtkTimerLog::GetCPUTime() - initialTime << " seconds" );
892 OnViewManagerAdded(SUIT_ViewManager* viewMgr)
894 QString type = viewMgr->getViewModel()->getType();
895 if ( type == VVTK_Viewer::Type() )
896 connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ),
897 this, SLOT( OnViewCreated( SUIT_ViewWindow* ) ) );
902 OnViewCreated(SUIT_ViewWindow* view)
904 SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>( view );
906 setProperty( viewWindow, "speed_increment" );
907 setProperty( viewWindow, "spacemouse_func1_btn" );
908 setProperty( viewWindow, "spacemouse_func2_btn" );
909 setProperty( viewWindow, "spacemouse_func3_btn" );
910 setProperty( viewWindow, "spacemouse_func4_btn" );
911 setProperty( viewWindow, "spacemouse_func5_btn" );
917 setProperty( SVTK_ViewWindow* viewWindow, const QString& pref )
922 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
923 SVTK_MainWindow* aMainWindow = viewWindow->getMainWindow();
925 if ( pref == "speed_increment" ) {
926 val = resMgr->integerValue( "VISU", pref, 10 );
927 aMainWindow->InvokeEvent( SVTK::SetSpeedIncrementEvent, &val );
929 else if ( pref == "spacemouse_func1_btn" ) {
930 val = resMgr->integerValue( "VISU", pref, 1 );
931 aMainWindow->InvokeEvent( SVTK::SetSMDecreaseSpeedEvent, &val );
933 else if ( pref == "spacemouse_func2_btn" ) {
934 val = resMgr->integerValue( "VISU", pref, 2 );
935 aMainWindow->InvokeEvent( SVTK::SetSMIncreaseSpeedEvent, &val );
937 else if ( pref == "spacemouse_func3_btn" ) {
938 val = resMgr->integerValue( "VISU", pref, 10 );
939 aMainWindow->InvokeEvent( VISU::SetSMDecreaseMagnificationEvent, &val );
941 else if ( pref == "spacemouse_func4_btn" ) {
942 val = resMgr->integerValue( "VISU", pref, 11 );
943 aMainWindow->InvokeEvent( VISU::SetSMIncreaseMagnificationEvent, &val );
945 else if ( pref == "spacemouse_func5_btn" ) {
946 val = resMgr->integerValue( "VISU", pref, 9 );
947 aMainWindow->InvokeEvent( SVTK::SetSMDominantCombinedSwitchEvent, &val );
953 setProperty( SVTK_ViewManager* vm, const QString& prop )
958 QPtrVector<SUIT_ViewWindow> windows = vm->getViews();
959 for ( int n = windows.count(), i = 0; i < n; i++ )
960 setProperty( dynamic_cast<SVTK_ViewWindow*>( windows[i] ), prop );
965 preferencesChanged( const QString& group, const QString& pref )
967 VisuGUI::preferencesChanged(group,pref);
969 if ( group == "VISU" && ( pref == "speed_increment" || pref == "spacemouse_func1_btn" ||
970 pref == "spacemouse_func2_btn" || pref == "spacemouse_func3_btn" ||
971 pref == "spacemouse_func4_btn" || pref == "spacemouse_func5_btn" ) ) {
973 // update properties of VVTK view windows
974 SUIT_ViewManager* vm = getApp()->getViewManager( VVTK_Viewer::Type(), false );
976 setProperty( dynamic_cast<SVTK_ViewManager*>( vm ), pref );
981 //---------------------------------------------------------------
984 getViewManager(const QString& theType,
985 const bool theIsCreate)
987 if (SUIT_ViewManager* aViewManager = VisuGUI::getViewManager(theType,theIsCreate))
990 if (theIsCreate && theType == VVTK_Viewer::Type())
991 return onCreateViewManager();
996 //---------------------------------------------------------------
1001 Handle(SALOME_InteractiveObject) anIO;
1002 if (VISU::Prs3d_i* aPrs3d = GetPrsToModify(this, &anIO)) {
1003 // Create VVTK_ViewWindow, if it does not exist
1004 if (VVTK_ViewWindow* aViewWindow = GetViewWindow<VVTK_Viewer>(this)) {
1005 EditPrs3d<VISU::GaussPoints_i, VisuGUI_GaussPointsDlg, 1>(this, anIO, aPrs3d, aViewWindow);
1011 //---------------------------------------------------------------
1015 GetViewParams(VVTK_MainWindow* theViewWindow,
1016 const char* theSuffix,
1017 std::ostringstream& theStr)
1020 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1021 aRenderer->GetBackground(aColor);
1022 Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".R",aColor[0]);
1023 Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".G",aColor[1]);
1024 Storable::DataToStream(theStr,std::string("myColor") + theSuffix + ".B",aColor[2]);
1026 double aPosition[3];
1027 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1028 aCamera->GetPosition(aPosition);
1029 Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[0]",aPosition[0]);
1030 Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[1]",aPosition[1]);
1031 Storable::DataToStream(theStr,std::string("myPosition") + theSuffix + "[2]",aPosition[2]);
1033 double aFocalPnt[3];
1034 aCamera->GetFocalPoint(aFocalPnt);
1035 Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[0]",aFocalPnt[0]);
1036 Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[1]",aFocalPnt[1]);
1037 Storable::DataToStream(theStr,std::string("myFocalPnt") + theSuffix + "[2]",aFocalPnt[2]);
1040 aCamera->GetViewUp(aViewUp);
1041 Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[0]",aViewUp[0]);
1042 Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[1]",aViewUp[1]);
1043 Storable::DataToStream(theStr,std::string("myViewUp") + theSuffix + "[2]",aViewUp[2]);
1045 float aParallelScale = aCamera->GetParallelScale();
1046 Storable::DataToStream(theStr,std::string("myParallelScale") + theSuffix,aParallelScale);
1048 double aScaleFactor[3];
1049 theViewWindow->GetScale(aScaleFactor);
1050 Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[0]",aScaleFactor[0]);
1051 Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[1]",aScaleFactor[1]);
1052 Storable::DataToStream(theStr,std::string("myScaleFactor") + theSuffix + "[2]",aScaleFactor[2]);
1055 //---------------------------------------------------------------
1057 SetViewParams(VVTK_MainWindow* theViewWindow,
1058 const char* theSuffix,
1059 const Storable::TRestoringMap& theMap)
1062 aColor[0] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".R").toDouble();
1063 aColor[1] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".G").toDouble();
1064 aColor[2] = Storable::FindValue(theMap,std::string("myColor") + theSuffix + ".B").toDouble();
1065 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1066 aRenderer->SetBackground(aColor);
1068 double aPosition[3];
1069 aPosition[0] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[0]").toDouble();
1070 aPosition[1] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[1]").toDouble();
1071 aPosition[2] = Storable::FindValue(theMap,std::string("myPosition") + theSuffix + "[2]").toDouble();
1072 vtkCamera* aCamera = aRenderer->GetActiveCamera();
1073 aCamera->SetPosition(aPosition);
1075 double aFocalPnt[3];
1076 aFocalPnt[0] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[0]").toDouble();
1077 aFocalPnt[1] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[1]").toDouble();
1078 aFocalPnt[2] = Storable::FindValue(theMap,std::string("myFocalPnt") + theSuffix + "[2]").toDouble();
1079 aCamera->SetFocalPoint(aFocalPnt);
1082 aViewUp[0] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[0]").toDouble();
1083 aViewUp[1] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[1]").toDouble();
1084 aViewUp[2] = Storable::FindValue(theMap,std::string("myViewUp") + theSuffix + "[2]").toDouble();
1085 aCamera->SetViewUp(aViewUp);
1087 float aParallelScale = Storable::FindValue(theMap,std::string("myParallelScale") + theSuffix).toDouble();
1088 aCamera->SetParallelScale(aParallelScale);
1090 double aScaleFactor[3];
1091 aScaleFactor[0] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[0]").toDouble();
1092 aScaleFactor[1] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[1]").toDouble();
1093 aScaleFactor[2] = Storable::FindValue(theMap,std::string("myScaleFactor") + theSuffix + "[2]").toDouble();
1094 theViewWindow->SetScale(aScaleFactor);
1097 //---------------------------------------------------------------
1099 GetViewParams(VVTK_MainWindow1* theViewWindow,
1100 std::ostringstream& theStr)
1102 GetViewParams(theViewWindow,"1",theStr);
1104 VISU_WidgetCtrl* aWidgetCtrl = theViewWindow->GetWidgetCtrl();
1105 if(aWidgetCtrl->GetEnabled()){
1106 std::string aSegmentationMode;
1107 if(aWidgetCtrl->IsPlanesActive()){
1108 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1110 aPlanesWidget->GetOrigin(anOrigin);
1111 Storable::DataToStream(theStr,"myCursorOrigin[0]",anOrigin[0]);
1112 Storable::DataToStream(theStr,"myCursorOrigin[1]",anOrigin[1]);
1113 Storable::DataToStream(theStr,"myCursorOrigin[2]",anOrigin[2]);
1116 aPlanesWidget->GetNormal(aNormal);
1117 Storable::DataToStream(theStr,"myCursorNormal[0]",aNormal[0]);
1118 Storable::DataToStream(theStr,"myCursorNormal[1]",aNormal[1]);
1119 Storable::DataToStream(theStr,"myCursorNormal[2]",aNormal[2]);
1121 float aDepth = aPlanesWidget->Distance();
1122 Storable::DataToStream(theStr,"myCursorDepth",aDepth);
1124 aSegmentationMode = "Planes";
1125 }else if(aWidgetCtrl->IsSphereActive()){
1126 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1128 aSphereWidget->GetCenter(aCenter);
1129 Storable::DataToStream(theStr,"mySphereCursorCenter[0]",aCenter[0]);
1130 Storable::DataToStream(theStr,"mySphereCursorCenter[1]",aCenter[1]);
1131 Storable::DataToStream(theStr,"mySphereCursorCenter[2]",aCenter[2]);
1133 float aRadius = aSphereWidget->GetRadius();
1134 Storable::DataToStream(theStr,"mySphereCursorRaduis",aRadius);
1136 aSegmentationMode = "Sphere";
1139 Storable::DataToStream(theStr,"mySegmentationMode",aSegmentationMode);
1143 //---------------------------------------------------------------
1145 SetViewParams(VVTK_MainWindow1* theViewWindow,
1146 const Storable::TRestoringMap& theMap)
1148 SetViewParams(theViewWindow,"1",theMap);
1152 //---------------------------------------------------------------
1154 GetViewParams(VVTK_MainWindow2* theViewWindow,
1155 std::ostringstream& theStr)
1157 GetViewParams(theViewWindow,"2",theStr);
1161 SetViewParams(VVTK_MainWindow2* theViewWindow,
1162 const Storable::TRestoringMap& theMap)
1164 SetViewParams(theViewWindow,"2",theMap);
1168 //---------------------------------------------------------------
1170 GetViewParams(VVTK_ViewWindow* theViewWindow)
1172 std::ostringstream aStream;
1174 Storable::DataToStream(aStream,"myComment","GAUSSVIEW");
1176 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1177 Selection_Mode aSelectionMode = aSelector->SelectionMode();
1178 Storable::DataToStream(aStream,"mySelectionMode",aSelectionMode);
1180 GetViewParams(theViewWindow->getMainWindow1(),aStream);
1181 GetViewParams(theViewWindow->getMainWindow2(),aStream);
1183 return aStream.str();
1186 //---------------------------------------------------------------
1194 myIsSelected(false),
1200 typedef std::map<std::string,TSelection> TVisibleEntries;
1202 struct TGetVisibleEntries
1204 TVisibleEntries& myVisibleEntries;
1206 TGetVisibleEntries(TVisibleEntries& theVisibleEntries):
1207 myVisibleEntries(theVisibleEntries)
1211 operator()(VISU_GaussPtsAct* theActor)
1213 if(theActor->GetVisibility()){
1214 const Handle(SALOME_InteractiveObject)& anIO = theActor->getIO();
1215 myVisibleEntries.insert(TVisibleEntries::value_type(anIO->getEntry(),TSelection()));
1221 GetGaussPointsSelection(VVTK_ViewWindow* theViewWindow,
1222 TVisibleEntries& theVisibleEntries)
1224 // First find all visible Gauss Points presentations
1225 vtkRenderer* aRenderer = theViewWindow->getRenderer();
1226 vtkActorCollection* anActors = aRenderer->GetActors();
1227 TGetVisibleEntries aGetVisibleEntries(theVisibleEntries);
1228 SVTK::ForEach<VISU_GaussPtsAct>(anActors,
1229 aGetVisibleEntries);
1231 // Next, find the sub-ids for the visible Gauss Points presentations
1232 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1233 const SALOME_ListIO& aListIO = aSelector->StoredIObjects();
1234 SALOME_ListIteratorOfListIO anIter(aListIO);
1235 for(; anIter.More(); anIter.Next()){
1236 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
1237 std::string anEntry = anIO->getEntry();
1238 TVisibleEntries::iterator anEntriesIter = theVisibleEntries.find(anEntry);
1239 if(anEntriesIter != theVisibleEntries.end()){
1240 TSelection& aSelection = anEntriesIter->second;
1241 aSelection.myIsSelected = true;
1242 TColStd_IndexedMapOfInteger anIndexes;
1243 aSelector->GetIndex(anIO,anIndexes);
1244 if(anIndexes.Extent() > 0){
1245 aSelection.myHasSubId = true;
1246 aSelection.mySubId = anIndexes(1);
1253 //---------------------------------------------------------------
1256 CreateReference(_PTR(Study) theStudyDocument,
1257 _PTR(StudyBuilder) theStudyBuilder,
1258 _PTR(SObject) theFatherSObject,
1259 const string& theRefEntry,
1260 const TSelection& theSelection)
1262 _PTR(SObject) aNewObj = theStudyBuilder->NewObject(theFatherSObject);
1263 _PTR(SObject) aRefSObj = theStudyDocument->FindObjectID(theRefEntry);
1264 theStudyBuilder->Addreference(aNewObj,aRefSObj);
1266 std::ostringstream aStream;
1267 Storable::DataToStream(aStream,"myIsSelected",theSelection.myIsSelected);
1268 Storable::DataToStream(aStream,"myHasSubId",theSelection.myHasSubId);
1269 Storable::DataToStream(aStream,"mySubId",theSelection.mySubId);
1271 _PTR(GenericAttribute) anAttr;
1272 anAttr = theStudyBuilder->FindOrCreateAttribute(aNewObj,"AttributeComment");
1273 _PTR(AttributeComment) aComment(anAttr);
1274 aComment->SetValue(aStream.str());
1278 //---------------------------------------------------------------
1280 SetGaussPointsSelection(VisuGUI* theModule,
1281 VVTK_ViewWindow* theViewWindow,
1282 _PTR(Study) theCStudy,
1283 _PTR(SObject) theSObject)
1285 SVTK_Selector* aSelector = theViewWindow->GetSelector();
1286 aSelector->ClearIObjects();
1288 bool anIsFirst = true;
1289 _PTR(ChildIterator) aChildIter = theCStudy->NewChildIterator(theSObject);
1290 for (; aChildIter->More(); aChildIter->Next()) {
1291 _PTR(SObject) aChildSObject = aChildIter->Value();
1292 _PTR(SObject) aSObject;
1293 if(aChildSObject->ReferencedObject(aSObject)){
1294 CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject);
1295 PortableServer::ServantBase_var aServant = VISU::GetServant(anObject);
1296 if(VISU::Prs3d_i* aPrs3d = dynamic_cast<VISU::Prs3d_i*>(aServant.in())){
1298 VISU::UpdateViewer(theModule, aPrs3d, /*disp_only = */anIsFirst, /*highlight = */false);
1301 // To update selection
1302 _PTR(GenericAttribute) anAttr;
1303 if(aChildSObject->FindAttribute(anAttr,"AttributeComment")){
1304 _PTR(AttributeComment) aComment(anAttr);
1306 QString aStream(aComment->Value().c_str());
1307 Storable::TRestoringMap aMap;
1308 Storable::StrToMap(aStream,aMap);
1310 bool anIsSelected = Storable::FindValue(aMap,"myIsSelected").toInt();
1311 bool aHasSubId = Storable::FindValue(aMap,"myHasSubId").toInt();
1312 int aSubId = Storable::FindValue(aMap,"mySubId").toInt();
1315 std::string anEntry = aSObject->GetID();
1316 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(anEntry.c_str(),"");
1317 aSelector->AddIObject(anIO);
1319 aSelector->AddOrRemoveIndex(anIO,aSubId,false);
1326 aSelector->EndPickCallback(); // To invoke selection changed signal
1330 //---------------------------------------------------------------
1332 OnStoreConfiguration(SalomeApp_Module* theModule,
1335 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1336 if (CheckLock(aCStudy,GetDesktop(theModule)))
1339 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(theModule);
1341 SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager();
1342 if(aViewManager->getType() == VVTK_Viewer::Type()){
1343 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1344 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1346 SUIT_Study* aSStudy = aViewManager->study();
1347 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(aSStudy);
1348 _PTR(Study) aCStudy = aStudy->studyDS();
1349 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1351 std::string anEntry;
1352 std::string aValue = GetViewParams(aViewWindow);
1355 _PTR(SComponent) aSComponent = ClientFindOrCreateVisuComponent(aCStudy);
1357 static int myNbConfigs = 0;
1358 std::string aName = VISU::GenerateName("Config.", ++myNbConfigs).latin1();
1360 std::string aSComponentEntry = aSComponent->GetID();
1361 anEntry = CreateAttributes(aCStudy,
1362 aSComponentEntry.c_str(),
1369 SALOME_ListIO aListIO;
1370 aSelectionMgr->selectedObjects(aListIO);
1371 SALOME_ListIteratorOfListIO aListIter( aListIO );
1372 for(; aListIter.More(); aListIter.Next()){
1373 Handle(SALOME_InteractiveObject) anIO = aListIter.Value();
1374 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1375 _PTR(GenericAttribute) anAttr;
1376 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1377 _PTR(AttributeComment) aComment(anAttr);
1378 std::string aCommentValue(aComment->Value());
1379 if(aCommentValue.compare("myComment=GAUSSVIEW") >= 0){
1380 aComment->SetValue(aValue.c_str());
1381 anEntry = aSObject->GetID();
1383 _PTR(ChildIterator) aChildIter = aCStudy->NewChildIterator(aSObject);
1384 for (; aChildIter->More(); aChildIter->Next()) {
1385 _PTR(SObject) aChildSObject = aChildIter->Value();
1386 aStudyBuilder->RemoveObject(aChildSObject);
1395 TVisibleEntries aVisibleEntries;
1396 GetGaussPointsSelection(aViewWindow,
1399 _PTR(SObject) aSObject = aCStudy->FindObjectID(anEntry);
1400 _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder();
1401 TVisibleEntries::const_iterator anIter = aVisibleEntries.begin();
1402 for(; anIter != aVisibleEntries.end(); anIter++){
1403 const std::string& anEntry = anIter->first;
1404 const TSelection& aSelection = anIter->second;
1406 CreateReference(aCStudy,
1413 //UpdateObjBrowser(theModule,true,aSObject);
1414 UpdateObjBrowser(theModule,true);
1420 //---------------------------------------------------------------
1421 template<class TMainWindow>
1423 SetMainWindowParams(VisuGUI* theModule,
1424 _PTR(SObject) theSObject,
1425 VVTK_ViewWindow* theViewWindow,
1426 TMainWindow* theMainWindow)
1428 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(theModule));
1430 _PTR(GenericAttribute) anAttr;
1431 if(theSObject->FindAttribute(anAttr,"AttributeComment")){
1432 _PTR(AttributeComment) aComment(anAttr);
1433 QString aStream(aComment->Value().c_str());
1434 Storable::TRestoringMap aMap;
1435 Storable::StrToMap(aStream,aMap);
1436 SetViewParams(theMainWindow,aMap);
1442 //---------------------------------------------------------------
1445 OnSaveConfiguration()
1447 ::OnStoreConfiguration(this,true);
1451 //---------------------------------------------------------------
1454 OnOverwriteConfiguration()
1456 ::OnStoreConfiguration(this,false);
1460 //---------------------------------------------------------------
1463 OnRestoreConfiguration()
1465 LightApp_SelectionMgr* aSelectionMgr = GetSelectionMgr(this);
1467 SALOME_ListIO aListIO;
1468 aSelectionMgr->selectedObjects(aListIO);
1469 if(aListIO.Extent() > 1)
1472 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),true)){
1473 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
1474 _PTR(Study) aCStudy = GetCStudy(GetAppStudy(this));
1475 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
1476 myConfigSObject = aSObject;
1477 _PTR(GenericAttribute) anAttr;
1478 if(aSObject->FindAttribute(anAttr,"AttributeComment")){
1479 _PTR(AttributeComment) aComment(anAttr);
1480 QString aStream(aComment->Value().c_str());
1481 Storable::TRestoringMap aMap;
1482 Storable::StrToMap(aStream,aMap);
1483 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1484 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1486 Selection_Mode aSelectionMode = Storable::FindValue(aMap,"mySelectionMode").toInt();
1487 SVTK_Selector* aSelector = aViewWindow->GetSelector();
1488 aSelector->SetSelectionMode(aSelectionMode);
1490 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1492 std::string aSegmentationMode;
1493 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1494 aMainWindow->SetPlanesSegementation(false);
1495 aMainWindow->SetSphereSegementation(false);
1496 VISU_WidgetCtrl* aWidgetCtrl = aMainWindow->GetWidgetCtrl();
1497 aSegmentationMode = Storable::FindValue(aMap,"mySegmentationMode").latin1();
1499 if(aSegmentationMode == "Planes"){
1500 VISU_PlanesWidget *aPlanesWidget = aWidgetCtrl->GetPlanesWidget();
1502 anOrigin[0] = Storable::FindValue(aMap,"myCursorOrigin[0]").toDouble();
1503 anOrigin[1] = Storable::FindValue(aMap,"myCursorOrigin[1]").toDouble();
1504 anOrigin[2] = Storable::FindValue(aMap,"myCursorOrigin[2]").toDouble();
1505 aPlanesWidget->SetOrigin(anOrigin);
1508 aNormal[0] = Storable::FindValue(aMap,"myCursorNormal[0]").toDouble();
1509 aNormal[1] = Storable::FindValue(aMap,"myCursorNormal[1]").toDouble();
1510 aNormal[2] = Storable::FindValue(aMap,"myCursorNormal[2]").toDouble();
1511 aPlanesWidget->SetNormal(aNormal);
1513 float aDepth = Storable::FindValue(aMap,"myCursorDepth").toDouble();
1514 aPlanesWidget->SetDistance(aDepth);
1516 aMainWindow->SetPlanesSegementation(true);
1517 }else if(aSegmentationMode == "Sphere"){
1518 VISU_SphereWidget *aSphereWidget = aWidgetCtrl->GetSphereWidget();
1520 aCenter[0] = Storable::FindValue(aMap,"mySphereCursorCenter[0]").toDouble();
1521 aCenter[1] = Storable::FindValue(aMap,"mySphereCursorCenter[1]").toDouble();
1522 aCenter[2] = Storable::FindValue(aMap,"mySphereCursorCenter[2]").toDouble();
1523 aSphereWidget->SetCenter(aCenter);
1525 float aRadius = Storable::FindValue(aMap,"mySphereCursorRaduis").toDouble();
1526 aSphereWidget->SetRadius(aRadius);
1528 aMainWindow->SetSphereSegementation(true);
1532 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1533 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1534 if(anInteractor->isVisible()){
1535 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1537 anInteractor->installEventFilter(this);
1540 if(aSegmentationMode != ""){
1541 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1542 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1543 if(anInteractor->isVisible())
1544 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1546 anInteractor->installEventFilter(this);
1550 SetGaussPointsSelection(this,aViewWindow,aCStudy,aSObject);
1556 //---------------------------------------------------------------
1559 eventFilter( QObject * theWatched, QEvent * theEvent )
1561 bool aRet = VisuGUI::eventFilter(theWatched,theEvent);
1562 if(theEvent->type() == QEvent::Show){
1563 if(SUIT_ViewManager* aViewManager = getViewManager(VVTK_Viewer::Type(),false)){
1564 SUIT_ViewWindow* aWindow = aViewManager->getActiveView();
1565 VVTK_ViewWindow* aViewWindow = dynamic_cast<VVTK_ViewWindow*>(aWindow);
1566 if(VVTK_MainWindow1* aMainWindow = aViewWindow->getMainWindow1()){
1567 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1568 if(theWatched == anInteractor){
1569 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1570 anInteractor->removeEventFilter(this);
1573 if(VVTK_MainWindow2* aMainWindow = aViewWindow->getMainWindow2()){
1574 SVTK_RenderWindowInteractor* anInteractor = aMainWindow->GetInteractor();
1575 if(theWatched == aMainWindow->GetInteractor()){
1576 SetMainWindowParams(this,myConfigSObject,aViewWindow,aMainWindow);
1577 anInteractor->removeEventFilter(this);
1586 const char gSeparator = '_'; // character used to separate parameter names
1587 const char gDigitsSep = ':'; // character used to separate numeric parameter values (color = r:g:b)
1589 * \brief Virtual public
1591 * This method is called just before the study document is saved, so the module has a possibility
1592 * to store visual parameters in AttributeParameter attribue(s)
1594 void VisuGUI_Module::storeVisualParameters(int savePoint)
1596 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1597 if( !study || !study->studyDS() )
1599 _PTR(Study) studyDS = study->studyDS();
1600 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1601 SALOMEDS_IParameters ip(ap);
1603 // viewers counters are used for storing view_numbers in IParameters
1604 int svtkViewers( 0 ), vvtkViewers( 0 ), plotViewers( 0 );
1606 // componentName is used for encoding of entries when storing them in IParameters
1607 _PTR(SComponent) visuEng = ClientFindOrCreateVisuComponent( studyDS );
1608 std::string componentName = visuEng->ComponentDataType();
1610 QPtrList<SUIT_ViewManager> lst;
1612 // saving VVTK viewer parameters. VVTK (Gauss Viewers) are NOT created by SalomeApp since
1613 // VVTK is declared in VISU, so here we store VVTK view window parameters.
1614 // VisuGUI_Module::restoreVisualParameters() creates VVTK_Views and restores its parameters.
1615 ip.setProperty( "ActiveGaussViewer", "-1" );
1616 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
1617 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1618 SUIT_ViewManager* vman = it.current();
1619 if ( SUIT_ViewWindow* vwin = vman->getActiveView() ) {
1620 // using predefined string "GaussViewer" as "entry".. it's a hardcoded "workaround".
1621 // gauss viewer parameters are retrieved using this "entry" string.
1622 // name of parameter = caption of gauss ViewWindow
1623 // value of parameter = ViewWindow's visual parameters
1624 ip.setParameter( "GaussViewer", vwin->caption().latin1(), vwin->getVisualParameters().latin1() );
1626 if ( application()->desktop()->activeWindow() == vwin )
1627 ip.setProperty( "ActiveGaussViewer", QString::number( vvtkViewers ).latin1() );
1632 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1633 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we store if any is open..
1636 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1637 ip.setProperty( "VtkViewersCount", QString::number( lst.count() ).latin1() );
1640 // main cycle to store parameters of displayed objects
1642 getApp()->viewManagers( lst );
1643 vvtkViewers = svtkViewers = plotViewers = 0;
1644 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1645 SUIT_ViewManager* vman = it.current();
1646 QString vType = vman->getType();
1647 int* viewsCounter = vType == SVTK_Viewer::Type() ? &svtkViewers :
1648 vType == VVTK_Viewer::Type() ? &vvtkViewers :
1649 vType == SPlot2d_Viewer::Type() ? &plotViewers : 0;
1651 // saving VTK actors' properties
1652 if ( vType == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers in the same
1653 vType == VVTK_Viewer::Type() ) { // way (VVTK_ViewWindow inherits SVTK_ViewWindow)
1655 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1656 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1657 if ( SVTK_ViewWindow* vtkView = dynamic_cast<SVTK_ViewWindow*>( views[i] ) ) {
1658 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1659 allActors->InitTraversal();
1660 while ( vtkActor* actor = allActors->GetNextActor() ) {
1661 if ( actor->GetVisibility() ) { // store only visible actors
1662 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1663 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1665 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1666 // entry is "ecoded" = it does NOT contain component adress, since it is a
1667 // subject to change on next component loading
1668 std::string entry = ip.encodeEntry( io->getEntry(), componentName );
1670 std::string param, vtkParam = vType.latin1(); vtkParam += gSeparator;
1671 vtkParam += QString::number( *viewsCounter ).latin1(); vtkParam += gSeparator;
1673 param = vtkParam + "Visibility";
1674 ip.setParameter( entry, param, "On" );
1675 param = vtkParam + "Name";
1676 ip.setParameter( entry, param, vActor->getName() );
1677 param = vtkParam + "RepresentationMode";
1678 ip.setParameter( entry, param, QString::number( vActor->GetRepresentation() ).latin1() );
1679 param = vtkParam + "Opacity";
1680 ip.setParameter( entry, param, QString::number( vActor->GetOpacity() ).latin1() );
1682 vActor->GetColor(r, g, b);
1683 QString colorStr = QString::number( r ); colorStr += gDigitsSep;
1684 colorStr += QString::number( g ); colorStr += gDigitsSep;
1685 colorStr += QString::number( b );
1686 param = vtkParam + "Color";
1687 ip.setParameter( entry, param, colorStr.latin1() );
1688 param = vtkParam + "LineWidth";
1689 ip.setParameter( entry, param, QString::number( vActor->GetLineWidth() ).latin1() );
1690 if ( vActor->IsShrunkable() && vActor->IsShrunk() ) {
1691 param = vtkParam + "ShrinkMode";
1692 ip.setParameter( entry, param, "On" );
1693 param = vtkParam + "ShrinkFactor";
1694 ip.setParameter( entry, param, QString::number( vActor->GetShrinkFactor() ).latin1() );
1696 VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor );
1697 if ( scalarMapActor && scalarMapActor->IsShading() ) {
1698 param = vtkParam + "Shading";
1699 ip.setParameter( entry, param, "On" );
1701 if ( const VISU::Prs3d_i* vPrs = vActor->GetPrs3d() ) {
1702 param = vtkParam + "ClippingPlane_";
1703 for ( int p = 0, nPlanes = vPrs->GetNumberOfClippingPlanes(); p < nPlanes; p++ ) {
1704 vtkPlane* plane = vPrs->GetClippingPlane( p );
1705 float normal[3], origin[3];
1706 plane->GetNormal( normal );
1707 plane->GetOrigin( origin );
1708 std::string planeValue = QString::number( normal[0] ).latin1(); planeValue += gDigitsSep;
1709 planeValue += QString::number( normal[1] ).latin1(); planeValue += gDigitsSep;
1710 planeValue += QString::number( normal[2] ).latin1(); planeValue += gDigitsSep;
1711 planeValue += QString::number( origin[0] ).latin1(); planeValue += gDigitsSep;
1712 planeValue += QString::number( origin[1] ).latin1(); planeValue += gDigitsSep;
1713 planeValue += QString::number( origin[2] ).latin1();
1714 param += QString::number( p+1 ).latin1();
1715 ip.setParameter( entry, param, planeValue );
1720 } // salome_actor successfull downcast
1722 } // end of ..while.. actors traversal
1726 } // if ( SVTK view model )
1727 else if ( vType == SPlot2d_Viewer::Type() ) { // processing Plot2d viewers
1728 QPtrVector<SUIT_ViewWindow> views = vman->getViews();
1729 for ( int i = 0, iEnd = vman->getViewsCount(); i < iEnd; i++ ) {
1730 if ( Plot2d_ViewWindow* plotView = dynamic_cast<Plot2d_ViewWindow*>( views[i] ) ) {
1731 Plot2d_ViewFrame* plotVF = plotView->getViewFrame();
1732 QPtrList<Plot2d_Curve> curves;
1733 plotVF->getCurves( curves );
1735 Plot2d_Curve* curve;
1736 for ( curve = curves.first(); curve; curve = curves.next() ) {
1737 if ( SPlot2d_Curve* sCurve = dynamic_cast<SPlot2d_Curve*>( curve ) ) {
1738 if ( sCurve->hasIO() ) {
1740 Handle(SALOME_InteractiveObject) io = sCurve->getIO();
1741 // entry is "ecoded" = it does NOT contain component adress, since it is a
1742 // subject to change on next component loading
1743 std::string entry = ip.encodeEntry( io->getEntry(), componentName );
1745 std::string param, plotParam = vType.latin1(); plotParam += gSeparator;
1746 plotParam += QString::number( *viewsCounter ).latin1(); plotParam += gSeparator;
1748 param = plotParam + "Visibility";
1749 ip.setParameter( entry, param, "On" );
1753 } // if ( plotView )
1756 } // if ( SPlot2d view model )
1760 // returns VISU_Actor with IO with given entry
1761 VISU_Actor* getActor( const QString& entry, SVTK_ViewWindow* vtkView )
1763 if ( vtkView && !entry.isEmpty() ) {
1764 vtkActorCollection* allActors = vtkView->getRenderer()->GetActors();
1765 allActors->InitTraversal();
1766 while ( vtkActor* actor = allActors->GetNextActor() ) {
1767 if ( VISU_Actor* vActor = VISU_Actor::SafeDownCast( actor ) ) {
1768 if ( vActor->hasIO() ) { // actor corresponds to existing obj
1769 Handle(SALOME_InteractiveObject) io = vActor->getIO();
1770 if ( entry == io->getEntry() )
1779 const int ViewerType = 0;
1780 const int ViewIndex = 1;
1781 const int ParamName = 2;
1782 // visual parameters are stored in strings as follows:
1783 // ViewerType_ViewNumber_ParamName. '_' is used as separator and should not be used in
1784 // viewer type or parameter names
1786 // return viewer type substring from parameter name
1787 std::string getParam( const std::string& paramName, const int index )
1789 QStringList lst = QStringList::split( gSeparator, QString( paramName.c_str() ) );
1790 if ( !lst.isEmpty() && index < lst.size() )
1797 * \brief Virtual public
1799 * This method is called after the study document is opened, so the module has a possibility to restore
1802 void VisuGUI_Module::restoreVisualParameters(int savePoint)
1804 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
1805 if( !study || !study->studyDS() )
1807 _PTR(Study) studyDS = study->studyDS();
1808 _PTR(AttributeParameter) ap = studyDS->GetModuleParameters("Interface Applicative", moduleName().latin1(), savePoint);
1809 SALOMEDS_IParameters ip(ap);
1811 // actors are stored in a map after displaying of them for quicker access in future
1812 QMap<QString, QMap<QString, VISU_Actor*> > vtkActors; // map: entry to map: ViewType_<ID> to actor (SVTK/VVTK)
1814 std::vector<std::string> entries = ip.getEntries();
1816 for ( std::vector<std::string>::iterator entIt = entries.begin(); entIt != entries.end(); ++entIt ) {
1818 std::vector<std::string> paramNames = ip.getAllParameterNames( *entIt );
1819 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 if ( *entIt == "GaussViewer" ) {
1824 // parameter names are view window's captions, values - visual parameters.
1825 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1826 SUIT_ViewManager* vman = onCreateViewManager();
1827 SUIT_ViewWindow* vwin = vman->getActiveView();
1828 vwin->setCaption( (*namesIt).c_str() );
1830 // wait untill the window is really shown. This step fixes MANY bugs..
1831 while ( !vwin->isVisible() )
1832 qApp->processEvents();
1834 vwin->setVisualParameters( (*valuesIt).c_str() );
1836 continue; // skip to next entry
1839 // entry is a normal entry - it should be "decoded" (setting base adress of component)
1840 QString entry( ip.decodeEntry( *entIt ).c_str() );
1842 for ( ; namesIt != paramNames.end(); ++namesIt, ++valuesIt ) {
1843 std::string viewerType = ::getParam( *namesIt, ViewerType );
1845 std::string paramName = ::getParam( *namesIt, ParamName );
1847 std::string viewIndexStr = ::getParam( *namesIt, ViewIndex );
1848 int viewIndex = QString( viewIndexStr.c_str() ).toUInt( &ok );
1849 if ( !ok ) // bad conversion of view index to integer
1852 // cout << " -- " << viewerType << ": entry = " << entry.latin1() << ", paramName = " << paramName << endl;
1854 if ( viewerType == SVTK_Viewer::Type().latin1() ||
1855 viewerType == VVTK_Viewer::Type().latin1() ) {
1857 // used as inner map key for locating the actor.
1858 QString viewerTypeIndex = viewerType + QString::number( viewIndex );
1860 if ( paramName == "Visibility" && displayer() ) {
1861 // if VVTK, then we must create viewer first, because
1863 QPtrList<SUIT_ViewManager> lst;
1864 getApp()->viewManagers( viewerType, lst );
1866 // SVTK/VVTK ViewManager always has 1 ViewWindow, so view index is index of view manager
1867 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1868 SUIT_ViewManager* vman = lst.at( viewIndex );
1869 SUIT_ViewModel* vmodel = vman->getViewModel();
1870 // SVTK and VVTK view models can be casted to SALOME_View
1871 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1872 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1873 // vtkView->getRenderer()->ResetCameraClippingRange();
1874 // vtkView->Repaint();
1876 // store displayed actor so setting of color, opacity, etc. will be much faster
1877 QMap<QString, VISU_Actor*> viewActorMap;
1878 if ( vtkActors.contains( entry ) )
1879 viewActorMap = vtkActors[ entry ];
1880 viewActorMap[ viewerTypeIndex ] = getActor( entry, vtkView );
1881 vtkActors[ entry ] = viewActorMap;
1884 else { // the rest properties "work" with VISU_Actor, so we initialize it at first
1885 VISU_Actor* vActor = 0;
1886 if ( vtkActors.contains( entry ) ) {
1887 QMap<QString, VISU_Actor*> viewActorMap = vtkActors[ entry ];
1888 if ( viewActorMap.contains( viewerTypeIndex ) )
1889 vActor = viewActorMap[ viewerTypeIndex ];
1894 QString val( (*valuesIt).c_str() );
1896 if ( paramName == "Name" )
1897 vActor->setName( val.latin1() );
1899 else if ( paramName == "RepresentationMode" )
1900 vActor->SetRepresentation( val.toInt() );
1902 else if ( paramName == "Opacity" )
1903 vActor->SetOpacity( val.toFloat() );
1905 else if ( paramName == "Color" ) {
1906 QStringList colors = QStringList::split( gDigitsSep, val );
1907 if ( colors.count() == 3 )
1908 vActor->SetColor( colors[0].toFloat(), colors[1].toFloat(), colors[2].toFloat() );
1911 else if ( paramName == "LineWidth" )
1912 vActor->SetLineWidth( val.toFloat() );
1914 else if ( paramName == "ShrinkMode" ) {
1915 vActor->SetShrinkable( true );
1916 vActor->SetShrink();
1919 else if ( paramName == "ShrunkFactor" )
1920 vActor->SetShrinkFactor( val.toFloat() );
1922 else if ( paramName == "Shading" ) {
1923 if ( VISU_ScalarMapAct* scalarMapActor = dynamic_cast<VISU_ScalarMapAct*>( vActor ) )
1924 scalarMapActor->SetShading();
1927 else if ( paramName.find( "ClippingPlane" ) != std::string::npos ) {
1928 QStringList vals = QStringList::split( gDigitsSep, val );
1929 if ( vals.count() == 6 && vActor->GetPrs3d() ) {
1930 float normal[3], origin[3];
1931 for (int x = 0; x < 3; x++ ) {
1932 normal[x] = vals[x].toFloat();
1933 origin[x] = vals[x+3].toFloat();
1935 vtkPlane* plane = vtkPlane::New();
1936 plane->SetNormal( normal );
1937 plane->SetOrigin( origin );
1938 vActor->GetPrs3d()->AddClippingPlane( plane );
1944 else if ( viewerType == SPlot2d_Viewer::Type().latin1() ) {
1946 if ( paramName == "Visibility" && displayer() ) {
1947 QPtrList<SUIT_ViewManager> lst;
1948 getApp()->viewManagers( viewerType, lst );
1950 if ( viewIndex >= 0 && viewIndex < lst.count() ) {
1951 SUIT_ViewManager* vman = lst.at( viewIndex );
1952 SUIT_ViewModel* vmodel = vman->getViewModel();
1953 // SVTK and VVTK view models can be casted to SALOME_View
1954 displayer()->Display( entry, true, dynamic_cast<SALOME_View*>( vmodel ) );
1960 } // for names/parameters iterator
1961 } // for entries iterator
1963 // [ update all SVTK/VVTK views
1964 QPtrList<SUIT_ViewManager> lst;
1965 getApp()->viewManagers( lst );
1966 for ( QPtrListIterator<SUIT_ViewManager> it( lst ); it.current(); ++it ) {
1967 SUIT_ViewManager* vman = it.current();
1968 SUIT_ViewModel* vmodel = vman->getViewModel();
1971 if ( vmodel->getType() == SVTK_Viewer::Type() || // processing SVTK and VVTK viewers
1972 vmodel->getType() == VVTK_Viewer::Type() ) { // in the same way
1973 SVTK_ViewWindow* vtkView = (SVTK_ViewWindow*) vman->getActiveView();
1974 vtkView->getRenderer()->ResetCameraClippingRange();
1977 else if ( vmodel->getType() == SPlot2d_Viewer::Type().latin1() ) {
1978 Plot2d_ViewWindow* plotView = (Plot2d_ViewWindow*) vman->getActiveView();
1979 plotView->getViewFrame()->Repaint();
1981 } // ] end of update views
1983 // VISU module opens one SVTK viewer in activateModule(). This causes a bug in save-restore visual
1984 // parameters: it no SVTK view was saved, we need NOT any SVTK on restore. Here we close one
1985 // default SVTK if needed.
1987 QString openedSvtkViewerStr = ip.getProperty( "VtkViewersCount" ).c_str();
1988 int openedSvtkViewer = openedSvtkViewerStr.toInt( &ok );
1989 if ( ok && openedSvtkViewer == 0 ) {
1991 getApp()->viewManagers( SVTK_Viewer::Type(), lst );
1993 lst.at( 0 )->closeAllViews();
1997 // if active Gauss Viewer is set ( != -1) then raise the gauss view window.
1999 QString activeGaussViewerStr = ip.getProperty( "ActiveGaussViewer" ).c_str();
2000 int activeGaussViewer = activeGaussViewerStr.toInt( &ok );
2001 if ( ok && activeGaussViewer != -1 ) {
2003 getApp()->viewManagers( VVTK_Viewer::Type(), lst );
2004 if ( activeGaussViewer >= 0 && activeGaussViewer < lst.count() ) {
2005 SUIT_ViewWindow* activeView = lst.at( activeGaussViewer )->getActiveView();
2007 activeView->setActiveWindow();
2008 activeView->setFocus();