1 #include <OCCViewer_ViewModel.h>
3 #include "GEOMGUI_Selection.h"
4 #include "GEOM_Displayer.h"
5 #include "GEOMImpl_Types.hxx"
7 #include <SalomeApp_DataOwner.h>
8 #include <SalomeApp_Study.h>
10 #include <SUIT_Session.h>
11 #include <SUIT_ViewWindow.h>
12 #include <SUIT_ViewManager.h>
13 #include <SUIT_ViewModel.h>
15 #include <SALOMEDSClient_SObject.hxx>
16 #include <SALOMEDSClient_Study.hxx>
17 #include <SALOMEDS_SObject.hxx>
18 #include <SALOME_Prs.h>
19 #include <SALOME_InteractiveObject.hxx>
23 #include <OCCViewer_ViewModel.h>
26 #include <AIS_InteractiveObject.hxx>
27 #include <AIS_ListOfInteractive.hxx>
29 GEOMGUI_Selection::GEOMGUI_Selection()
33 GEOMGUI_Selection::~GEOMGUI_Selection()
37 QtxValue GEOMGUI_Selection::param( const int ind, const QString& p ) const
39 QtxValue val( SalomeApp_Selection::param( ind, p ) );
40 if ( !val.isValid() ) {
41 if ( p == "isVisible" ) val = QtxValue( isVisible( ind ) );
42 else if ( p == "isOCC" ) val = QtxValue( isOCC() );
43 else if ( p == "type" ) val = QtxValue( typeName( ind ) );
44 else if ( p == "displaymode" ) val = QtxValue( displayMode( ind ) );
47 //printf( "--> param() : [%s] = %s\n", p.latin1(), val.toString ().latin1() );
52 QString GEOMGUI_Selection::typeName( const int index ) const
54 if ( isComponent( index ) )
56 GEOM::GEOM_Object_var anObj = getObject( index );
57 if ( !CORBA::is_nil( anObj ) ) {
58 const int aGeomType = anObj->GetType();
59 if ( aGeomType == GEOM_GROUP )
67 bool GEOMGUI_Selection::isVisible( const int index ) const
69 GEOM::GEOM_Object_var obj = getObject( index );
70 SALOME_View* view = GEOM_Displayer::GetActiveView();
71 if ( !CORBA::is_nil( obj ) && view ) {
72 Handle(SALOME_InteractiveObject) io = new SALOME_InteractiveObject( entry( index ).latin1(), "GEOM", "TEMP_IO" );
73 return view->isVisible( io );
78 bool GEOMGUI_Selection::isOCC() const
80 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
81 return ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
84 QString GEOMGUI_Selection::displayMode( const int index ) const
86 SALOME_View* view = GEOM_Displayer::GetActiveView();
88 SALOME_Prs* prs = view->CreatePrs( entry( index ) );
90 if ( isOCC() ) { // assuming OCC
91 SOCC_Prs* occPrs = (SOCC_Prs*) prs;
92 AIS_ListOfInteractive lst;
93 occPrs->GetObjects( lst );
95 Handle(AIS_InteractiveObject) io = lst.First();
97 int dm = io->DisplayMode();
98 if ( dm == AIS_WireFrame )
100 else if ( dm == AIS_Shaded )
102 else { // return default display mode of AIS_InteractiveContext
103 OCCViewer_Viewer* occViewer = (OCCViewer_Viewer*) SUIT_Session::session()->activeApplication()->desktop(
104 )->activeWindow()->getViewManager()->getViewModel();
105 Handle(AIS_InteractiveContext) ic = occViewer->getAISContext();
106 dm = ic->DisplayMode();
107 if ( dm == AIS_WireFrame )
109 else if ( dm == AIS_Shaded )
115 else { // assuming VTK
123 bool GEOMGUI_Selection::isComponent( const int index ) const
125 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
126 (SUIT_Session::session()->activeApplication()->activeStudy());
128 if ( appStudy && index >= 0 && index < count() ) {
129 _PTR(Study) study = appStudy->studyDS();
130 QString anEntry = entry( index );
132 if ( study && !anEntry.isNull() ) {
133 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
134 if ( aSO && aSO->GetFatherComponent() )
135 return aSO->GetFatherComponent()->GetIOR() == aSO->GetIOR();
141 GEOM::GEOM_Object_ptr GEOMGUI_Selection::getObject( const int index ) const
143 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
144 (SUIT_Session::session()->activeApplication()->activeStudy());
146 if ( appStudy && index >= 0 && index < count() ) {
147 _PTR(Study) study = appStudy->studyDS();
148 QString anEntry = entry( index );
150 if ( study && !anEntry.isNull() ) {
151 _PTR(SObject) aSO( study->FindObjectID( anEntry.latin1() ) );
153 SALOMEDS_SObject* aDSObj = dynamic_cast<SALOMEDS_SObject*>( aSO.get() );
154 return GEOM::GEOM_Object::_narrow( aDSObj->GetObject() );
158 return GEOM::GEOM_Object::_nil();