1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Selection.cxx
24 // Author : Sergey Anikin
27 #include "VisuGUI_Selection.h"
29 #include "VisuGUI_ViewTools.h"
30 #include "VisuGUI_Tools.h"
32 #include "VISU_Result_i.hh"
33 #include "VISU_Gen_i.hh"
35 #include "VISU_Actor.h"
36 #include "VISU_ScalarMapAct.h"
38 #include "SalomeApp_Study.h"
39 #include "LightApp_Study.h"
40 #include "LightApp_Displayer.h"
44 //////////////////////////////////////////////////
45 // Class: VisuGUI_Selection
46 //////////////////////////////////////////////////
49 //---------------------------------------------------------------
50 QVariant VisuGUI_Selection::parameter( const int ind, const QString& p ) const
52 QVariant val( LightApp_Selection::parameter( ind, p ) );
53 if ( !val.isValid() ) {
54 if ( p == "type" ) val = QVariant( type( ind ) );
55 else if ( p == "nbComponents" ) val = QVariant( nbComponents( ind ) );
56 else if ( p == "medEntity" ) val = QVariant( medEntity( ind ) );
57 else if ( p == "medSource" ) val = QVariant( medSource( ind ) );
58 else if ( p == "representation" ) val = QVariant( representation( ind ) );
59 else if ( p == "nbTimeStamps" ) val = QVariant( nbTimeStamps( ind ) );
60 else if ( p == "nbChildren" ) val = QVariant( nbChildren( ind ) );
61 else if ( p == "nbNamedChildren") val = QVariant( nbNamedChildren( ind ) );
62 else if ( p == "isVisible" ) val = QVariant( isVisible( ind ) );
63 else if ( p == "isShrunk" ) val = QVariant( isShrunk( ind ) );
64 else if ( p == "hasActor" ) val = QVariant( hasActor( ind ) );
65 else if ( p == "isShading" ) val = QVariant( isShading( ind ) );
66 else if ( p == "isScalarMapAct" ) val = QVariant( isScalarMapAct( ind ) );
67 else if ( p == "isVisuComponent") val = QVariant( isVisuComponent( ind ) );
68 else if ( p == "fullResolution" ) val = QVariant( fullResolution( ind ) );
69 else if ( p == "mediumResolution" ) val = QVariant( mediumResolution( ind ) );
70 else if ( p == "lowResolution" ) val = QVariant( lowResolution( ind ) );
71 else if ( p == "resolutionState" ) val = QVariant( resolutionState( ind ) );
72 else if ( p == "isThereAreVisibleCurves" ) val = QVariant( findDisplayedCurves( ind, false ) );
73 else if ( p == "isThereAreHiddenCurves" ) val = QVariant( findDisplayedCurves( ind, true ) );
74 else if ( p == "hasCurves" ) val = QVariant( hasCurves( ind ) );
75 else if ( p == "isPlot2dViewer" ) val = QVariant( Plot2dViewerType( ind ) );
76 else if ( p == "isValuesLabeled" ) val = QVariant( isValuesLabeled( ind ) );
77 else if ( p == "isScalarBarVisible" ) val = QVariant( isScalarBarVisible( ind ) );
84 //---------------------------------------------------------------
85 // Macro for converting VISU enumeration items into corresponding strings
86 #define ENUM2STRING( x, y ) \
91 QString VisuGUI_Selection::type( const int ind ) const
94 SalomeApp_Study* aStudy = GetStudy();
98 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
99 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
101 VISU::Base_i* aBase = anObjectInfo.myBase;
103 VISU::VISUType aType = aBase->GetType();
104 if(aType == VISU::TCOLOREDPRS3DHOLDER){
105 CORBA::Object_var anObject = ClientSObjectToObject(anObjectInfo.mySObject);
106 VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject);
107 aType = aHolder->GetPrsType();
110 ENUM2STRING( aResStr, VISU::TVISUGEN );
111 ENUM2STRING( aResStr, VISU::TRESULT );
112 ENUM2STRING( aResStr, VISU::TTABLE );
113 ENUM2STRING( aResStr, VISU::TCURVE );
114 ENUM2STRING( aResStr, VISU::TCONTAINER );
115 ENUM2STRING( aResStr, VISU::TMESH );
116 ENUM2STRING( aResStr, VISU::TSCALARMAP );
117 ENUM2STRING( aResStr, VISU::TISOSURFACES );
118 ENUM2STRING( aResStr, VISU::TDEFORMEDSHAPE );
119 ENUM2STRING( aResStr, VISU::TSCALARMAPONDEFORMEDSHAPE );
120 ENUM2STRING( aResStr, VISU::TCUTPLANES );
121 ENUM2STRING( aResStr, VISU::TCUTLINES );
122 ENUM2STRING( aResStr, VISU::TVECTORS );
123 ENUM2STRING( aResStr, VISU::TSTREAMLINES );
124 ENUM2STRING( aResStr, VISU::TPLOT3D );
125 ENUM2STRING( aResStr, VISU::TANIMATION );
126 ENUM2STRING( aResStr, VISU::TPOINTMAP3D );
130 if(aResStr.isNull()){
131 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aMap);
133 ENUM2STRING( aResStr, VISU::TENTITY );
134 ENUM2STRING( aResStr, VISU::TFAMILY );
135 ENUM2STRING( aResStr, VISU::TGROUP );
136 ENUM2STRING( aResStr, VISU::TVIEW3D );
137 ENUM2STRING( aResStr, VISU::TFIELD );
138 ENUM2STRING( aResStr, VISU::TTIMESTAMP );
142 if(aResStr.isNull()){
144 QString aVal = VISU::Storable::FindValue(aMap, "myComment", &anIsExist);
145 if ( anIsExist && aVal != "MESH" )
146 aResStr = "VISU::T" + aVal;
153 //---------------------------------------------------------------
154 QString VisuGUI_Selection::nbComponents( const int ind ) const
157 SalomeApp_Study* aStudy = GetStudy();
161 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
162 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
165 QString aVal = VISU::Storable::FindValue(aMap,"myNumComponent",&isExist);
172 //---------------------------------------------------------------
173 QString VisuGUI_Selection::resolutions( const int ind ) const
176 SalomeApp_Study* aStudy = GetStudy();
180 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, entry( ind ).toLatin1().data());
181 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
184 QString aVal = VISU::Storable::FindValue(aMap,"myResolutions",&isExist);
192 //---------------------------------------------------------------
193 QString VisuGUI_Selection::resolution( const int ind, char theResoltuion ) const
197 QString aResolutions = resolutions( ind );
198 if(aResolutions.isEmpty())
201 if(aResolutions.indexOf(theResoltuion) != -1)
210 //---------------------------------------------------------------
211 QString VisuGUI_Selection::fullResolution( const int ind ) const
213 return resolution( ind, 'F');
217 //---------------------------------------------------------------
218 QString VisuGUI_Selection::mediumResolution( const int ind ) const
220 return resolution( ind, 'M');
224 //---------------------------------------------------------------
225 QString VisuGUI_Selection::lowResolution( const int ind ) const
227 return resolution( ind, 'L');
231 //---------------------------------------------------------------
232 QString VisuGUI_Selection::resolutionState( const int ind ) const
235 SalomeApp_Study* aStudy = GetStudy();
239 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, entry( ind ).toLatin1().data());
240 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
243 QString aVal = VISU::Storable::FindValue(aMap,"myState",&isExist);
245 if ( aVal.toInt() == VISU::Result::FULL )
247 if ( aVal.toInt() == VISU::Result::MEDIUM )
249 if ( aVal.toInt() == VISU::Result::LOW )
251 if ( aVal.toInt() == VISU::Result::HIDDEN )
259 //---------------------------------------------------------------
260 QString VisuGUI_Selection::medEntity( const int ind ) const
262 SalomeApp_Study* aStudy = GetStudy();
266 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
267 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
270 QString aVal = VISU::Storable::FindValue(aMap,"myEntityId",&isExist);
272 using namespace VISU;
273 TEntity anEntityId = TEntity(aVal.toInt());
276 return "NODE_ENTITY";
278 return "EDGE_ENTITY";
280 return "FACE_ENTITY";
282 return "CELL_ENTITY";
290 QString VisuGUI_Selection::medSource( const int ind ) const
292 _PTR(Study) aStudyDS = GetStudy()->studyDS();
293 if(_PTR(SObject) aSObject = aStudyDS->FindObjectID((const char*)entry(ind).toLatin1())){
294 VISU::Result_var aRes;
295 if(VISU::Result_i* aResult = CheckResult(myModule,aSObject,aRes)){
296 using namespace VISU;
297 Result_i::ECreationId aCreationId = aResult->GetCreationId();
299 case Result_i::eImportFile :
300 return "eImportFile";
301 case Result_i::eCopyAndImportFile :
302 return "eCopyAndImportFile";
303 case Result_i::eImportMed :
305 case Result_i::eImportMedField :
306 return "eImportMedField";
315 QString VisuGUI_Selection::nbTimeStamps( const int ind ) const
318 SalomeApp_Study* aStudy = GetStudy();
322 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, (const char*)entry( ind ).toLatin1());
323 VISU::Storable::TRestoringMap aMap = VISU::Storable::GetStorableMap(anObjectInfo.mySObject);
326 const QString& aVal = VISU::Storable::FindValue(aMap,"myNbTimeStamps",&isExist);
333 //----------------------------------------------------------------------------
334 template<class TPopupFunctor>
335 struct TPopupDispatcher
338 operator()(const SalomeApp_Module* theModule,
339 const QString& theEntry)
341 if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
342 QString aType = aViewManager->getType();
343 TPopupFunctor aFunctor;
344 if(aType == SVTK_Viewer::Type())
345 return aFunctor.template Get<SVTK_Viewer>(theModule, theEntry);
346 //else if(aType == VVTK_Viewer::Type())
347 //return aFunctor.template Get<VVTK_Viewer>(theModule, theEntry);
354 //----------------------------------------------------------------------------
355 template<class TViewer>
357 GetPrs3dSelectionInfo(const SalomeApp_Module* theModule,
358 const QString& theEntry,
359 VISU::Prs3d_i*& thePrs3d,
360 SVTK_ViewWindow*& theViewWindow,
361 VISU_Actor*& thenActor)
363 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(GetAppStudy(theModule), (const char*)theEntry.toLatin1());
364 thePrs3d = GetPrs3dFromBase(anObjectInfo.myBase);
368 typedef typename TViewer::TViewWindow TViewWindow;
369 theViewWindow = GetActiveViewWindow<TViewWindow>(theModule);
373 thenActor = FindActor(theViewWindow, thePrs3d);
381 //----------------------------------------------------------------------------
384 template<class TViewer>
386 Get(const SalomeApp_Module* theModule,
387 const QString& theEntry)
389 VISU_Actor* anActor = NULL;
390 VISU::Prs3d_i* aPrs3d = NULL;
391 VISU_ActorBase* anActorBase = NULL;
392 VISU::PointMap3d_i* aPointMap3d = NULL;
393 SVTK_ViewWindow* aViewWindow = NULL;
394 if(GetPrs3dSelectionInfo<TViewer>(theModule, theEntry, aPrs3d, aViewWindow, anActor))
395 return get(aPrs3d, aViewWindow, anActor);
397 aViewWindow = GetActiveViewWindow<SVTK_ViewWindow>(theModule);
398 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(theModule);
399 if ( aSelectionInfo.empty() )
401 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
402 aPointMap3d = dynamic_cast<VISU::PointMap3d_i*>(aSelectionItem.myObjectInfo.myBase);
403 anActorBase = VISU::FindActorBase(aViewWindow, aPointMap3d);
404 return getPointMap(aPointMap3d, aViewWindow, anActorBase);
410 get(VISU::Prs3d_i* thePrs3d,
411 SVTK_ViewWindow* theViewWindow,
412 VISU_Actor* theActor)
419 getPointMap(VISU::PointMap3d_i* thePrs3d,
420 SVTK_ViewWindow* theViewWindow,
421 VISU_ActorBase* theActor)
428 //----------------------------------------------------------------------------
429 struct TGetRepesentationFunctor: TViewFunctor
433 get(VISU::Prs3d_i* thePrs3d,
434 SVTK_ViewWindow* theViewWindow,
435 VISU_Actor* theActor)
438 switch (theActor->GetRepresentation()) {
439 ENUM2STRING( aResStr, VISU::POINT );
440 ENUM2STRING( aResStr, VISU::WIREFRAME );
441 ENUM2STRING( aResStr, VISU::SHADED );
442 ENUM2STRING( aResStr, VISU::INSIDEFRAME );
443 ENUM2STRING( aResStr, VISU::SURFACEFRAME );
444 ENUM2STRING( aResStr, VISU::FEATURE_EDGES );
451 getPointMap(VISU::PointMap3d_i* thePrs3d,
452 SVTK_ViewWindow* theViewWindow,
453 VISU_ActorBase* theActorBase)
455 QString aResStr = "";
457 switch (theActorBase->GetRepresentation()) {
458 ENUM2STRING( aResStr, VISU::WIREFRAME ); // = 1
459 ENUM2STRING( aResStr, VISU::SHADED ); // = 2
466 QString VisuGUI_Selection::representation( const int ind ) const
468 return TPopupDispatcher<TGetRepesentationFunctor>()(myModule, entry(ind));
471 //----------------------------------------------------------------------------
472 SalomeApp_Study* VisuGUI_Selection::GetStudy() const
475 LightApp_Study* aLightStudy = const_cast<LightApp_Study*>( study() );
476 return dynamic_cast<SalomeApp_Study*>( aLightStudy );
479 //----------------------------------------------------------------------------
480 int VisuGUI_Selection::nbChild( const int ind, const bool named ) const
483 SalomeApp_Study* aSStudy = GetStudy();
486 _PTR(Study) aStudy = GetCStudy( aSStudy );
488 _PTR(SObject) SO = aStudy->FindObjectID( (const char*)entry( ind ).toLatin1() );
490 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
492 if ( !Iter->Value()->ReferencedObject( refSO ) && ( !named || Iter->Value()->GetName().size() ) )
500 //----------------------------------------------------------------------------
501 int VisuGUI_Selection::nbChildren( const int ind ) const
503 return nbChild( ind, false );
506 //----------------------------------------------------------------------------
507 int VisuGUI_Selection::nbNamedChildren( const int ind ) const
509 return nbChild( ind, true );
513 //----------------------------------------------------------------------------
514 struct TIsVisibleFunctor: TViewFunctor
518 get(VISU::Prs3d_i* thePrs3d,
519 SVTK_ViewWindow* theViewWindow,
520 VISU_Actor* theActor)
522 return theActor->GetVisibility() ? "true" : "false";
526 QString VisuGUI_Selection::isVisible( const int ind ) const
528 return TPopupDispatcher<TIsVisibleFunctor>()(myModule, entry(ind));
532 //----------------------------------------------------------------------------
533 struct TIsShrunkFunctor: TViewFunctor
537 get(VISU::Prs3d_i* thePrs3d,
538 SVTK_ViewWindow* theViewWindow,
539 VISU_Actor* theActor)
541 return theActor->IsShrunk() ? "1" : "0";
546 getPointMap(VISU::PointMap3d_i* thePointMap,
547 SVTK_ViewWindow* theViewWindow,
548 VISU_ActorBase* theActorBase)
551 return theActorBase->IsShrunk() ? "1" : "0";
556 QString VisuGUI_Selection::isShrunk( const int ind ) const
558 return TPopupDispatcher<TIsShrunkFunctor>()(myModule, entry(ind));
562 //----------------------------------------------------------------------------
563 bool VisuGUI_Selection::hasActor( const int ind ) const
565 return !representation( ind ).isEmpty();
569 //----------------------------------------------------------------------------
570 struct TIsShadingFunctor: TViewFunctor
574 get(VISU::Prs3d_i* thePrs3d,
575 SVTK_ViewWindow* theViewWindow,
576 VISU_Actor* theActor)
578 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor))
579 return anActor->IsShading() ? "1" : "0";
584 QString VisuGUI_Selection::isShading( const int ind ) const
586 return TPopupDispatcher<TIsShadingFunctor>()(myModule, entry(ind));
590 //----------------------------------------------------------------------------
591 struct TIsScalarMapActFunctor: TViewFunctor
595 get(VISU::Prs3d_i* thePrs3d,
596 SVTK_ViewWindow* theViewWindow,
597 VISU_Actor* theActor)
599 return dynamic_cast<VISU_ScalarMapAct*>(theActor)? "1" : "0";
604 //---------------------------------------------------------------
605 QString VisuGUI_Selection::isScalarMapAct( const int ind ) const
607 return TPopupDispatcher<TIsScalarMapActFunctor>()(myModule, entry(ind));
611 //----------------------------------------------------------------------------
612 bool VisuGUI_Selection::isVisuComponent( const int ind ) const
614 SalomeApp_Study* study = GetStudy();
618 _PTR(SObject) obj = study->studyDS()->FindObjectID( (const char*)entry( ind ).toLatin1() );
621 CORBA::Object_var anObj = VISU::ClientSObjectToObject( obj );
622 if( CORBA::is_nil( anObj ) )
625 return dynamic_cast<VISU::VISU_Gen_i*>( VISU::GetServant( anObj ).in() );
628 //---------------------------------------------------------------------------
629 bool VisuGUI_Selection::findDisplayedCurves( const int ind, bool findHidden ) const
631 // findHidden == false - find at least one Visible curve in the childs of ind
632 // findHidden == true - find at least one Hidden curve in the childs of ind
633 SalomeApp_Study* aSStudy = GetStudy();
638 _PTR(Study) aStudy = GetCStudy( aSStudy );
640 _PTR(SObject) SO = aStudy->FindObjectID( (const char*) entry( ind ).toLatin1() );
642 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
644 if ( Iter->Value()->ReferencedObject(refSO) )
645 entryId = refSO->GetID().c_str();
647 entryId = Iter->Value()->GetID().c_str();
649 LightApp_Displayer* displayer = LightApp_Displayer::FindDisplayer( myModule->moduleName(), false );
650 if ( displayer->IsDisplayed( entryId ) && findHidden == false )
652 else if ( !displayer->IsDisplayed( entryId ) && findHidden == true )
660 //---------------------------------------------------------------------------
661 bool VisuGUI_Selection::hasCurves( const int ind ) const
663 SalomeApp_Study* aSStudy = GetStudy();
668 _PTR(Study) aStudy = GetCStudy( aSStudy );
670 _PTR(SObject) SO = aStudy->FindObjectID( (const char*) entry( ind ).toLatin1() );
672 for ( _PTR(ChildIterator) Iter = aStudy->NewChildIterator( SO ); Iter->More(); Iter->Next() ) {
674 if ( Iter->Value()->ReferencedObject(refSO) ) {
675 // reference on curve
678 refSO = Iter->Value();
680 CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(refSO);
681 if(!CORBA::is_nil(aCORBAObject)){
682 PortableServer::ServantBase_var aServant = VISU::GetServant(aCORBAObject);
683 if(dynamic_cast<VISU::Curve_i*>(aServant.in()))
692 //---------------------------------------------------------------------------
693 bool VisuGUI_Selection::Plot2dViewerType( const int ind ) const
696 SUIT_Session* session = SUIT_Session::session();
697 if( SUIT_Application* app = session->activeApplication() )
698 if( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) )
699 if( SUIT_ViewManager* vman = sApp->activeViewManager() )
700 if( SUIT_ViewModel* vmod = vman->getViewModel() ) {
701 viewerType = vmod->getType();
702 if (viewerType ==SPlot2d_Viewer::Type())
708 //----------------------------------------------------------------------------
709 struct TIsValuesLabeled : TViewFunctor
713 get(VISU::Prs3d_i* thePrs3d,
714 SVTK_ViewWindow* theViewWindow,
715 VISU_Actor* theActor)
717 return theActor && theActor->GetValuesLabeled() ? "true" : "false";
721 QString VisuGUI_Selection::isValuesLabeled( const int ind ) const
723 return TPopupDispatcher<TIsValuesLabeled>()(myModule, entry(ind));
726 //----------------------------------------------------------------------------
727 struct TIsScalarBarVisibleFunctor: TViewFunctor
731 get(VISU::Prs3d_i* thePrs3d,
732 SVTK_ViewWindow* theViewWindow,
733 VISU_Actor* theActor)
735 if(VISU_ScalarMapAct* anActor = dynamic_cast<VISU_ScalarMapAct*>(theActor))
736 return anActor->GetBarVisibility() ? "true" : "false";
741 bool VisuGUI_Selection::isScalarBarVisible( const int ind ) const
743 return TPopupDispatcher<TIsScalarBarVisibleFunctor>()(myModule, entry(ind)) == "true";