1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <BRepTools.hxx>
27 #include <vtkRenderer.h>
28 #include <vtkActorCollection.h>
29 #include <vtkUnstructuredGrid.h>
33 #include <SUIT_Session.h>
35 #include <SalomeApp_Study.h>
36 #include <SalomeApp_Application.h>
37 // #include <SALOME_Actor.h>
38 // #include <SALOME_ListIO.hxx>
39 // #include <SALOME_ListIteratorOfListIO.hxx>
43 #include <OCCViewer_ViewWindow.h>
46 // #include <SALOMEconfig.h>
47 // #include "SALOME_Component_i.hxx"
48 // #include <omniORB4/CORBA.h>
51 #include <SVTK_ViewManager.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
55 #include <SALOME_Actor.h>
56 #include <VTKViewer_Algorithm.h>
59 #include "GeometryGUI.h"
60 #include CORBA_CLIENT_HEADER(GEOM_Gen)
63 #include "HEXABLOCKGUI.hxx"
64 #include "HEXABLOCKGUI_SalomeTools.hxx"
70 // using namespace HEXABLOCK::GUI;
78 SUIT_Study* GetActiveStudy()
80 SUIT_Application* app = SUIT_Session::session()->activeApplication();
82 return app->activeStudy();
88 _PTR(Study) GetActiveStudyDocument()
90 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
92 return aStudy->studyDS();
98 CORBA::Object_var corbaObj( _PTR(SObject) theSO )
100 //std::cout<< "corbaObj( _PTR(SObject) theSO )" << std::endl;
101 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
103 //std::cout<< "theSO" << std::endl;
104 std::string aValue = theSO->GetIOR();
105 //std::cout<< "aValue" << std::endl;
106 if (strcmp(aValue.c_str(), "") != 0) {
107 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
108 //std::cout<< "anORB" << anORB << std::endl;
109 aCorbaObj = anORB->string_to_object(aValue.c_str());
110 //std::cout<< "aCorbaObj" << aCorbaObj << std::endl;
111 // anDoc = Document::_narrow(aCorbaObj);
114 return aCorbaObj._retn();
118 CORBA::Object_var corbaObj( const Handle(SALOME_InteractiveObject)& theIO )
120 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
122 if ( !theIO.IsNull() && theIO->hasEntry() ){
123 _PTR(Study) aStudy = GetActiveStudyDocument();
124 _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
125 aCorbaObj = corbaObj(aSObj);
127 return aCorbaObj._retn();
131 std::string name( _PTR(SObject) theSO )
133 std::cout << "name( _PTR(SObject) theSO )"<< theSO;
134 std::string aResName;
137 _PTR(GenericAttribute) anAttr;
138 _PTR(AttributeName) aNameAttr;
139 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
141 std::cout << "FindAttribute";
143 std::cout << "aNameAttr = anAttr";
144 aResName = aNameAttr->Value().c_str();
151 std::string name( const std::string& entry )
153 std::cout << "name( const std::string& entry )"<< entry;
154 std::string aResName;
156 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
158 std::cout << "appStudy => "<< appStudy ;
159 _PTR(Study) aStudy = appStudy->studyDS();
160 std::cout << "aStudy=> "<< appStudy ;
161 _PTR(SObject) obj( aStudy->FindObjectID( entry ) );
162 std::cout << "obj=> "<< obj;
163 aResName = name( obj );
172 SALOME_Actor* findActorByEntry( SVTK_ViewWindow *theVtkViewWindow, const char* theEntry)
174 // SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
175 SALOME_Actor *foundActor = NULL;
176 vtkActor *aVTKActor = NULL;
177 Handle(SALOME_InteractiveObject) anIO;
179 vtkRenderer *aRenderer = theVtkViewWindow->getRenderer();
180 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
181 vtkActorCollection *aCollection = aCopy.GetActors();
182 aCollection->InitTraversal();
183 while( aVTKActor = aCollection->GetNextActor() ){
184 // if ( anAct->IsA("GEOM_Actor") ) std::cout<<"is an actor"<< std::endl;
185 foundActor = dynamic_cast<SALOME_Actor*>( aVTKActor );
186 if ( foundActor && foundActor->hasIO() ){
187 anIO = foundActor->getIO();
188 if( anIO->hasEntry() && strcmp(anIO->getEntry(), theEntry) == 0 )
193 return NULL; // no actor found
200 SVTK_ViewWindow* GetActiveVTKViewWindow()
202 SVTK_ViewWindow* aVtkView = NULL;
203 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
204 ( SUIT_Session::session()->activeApplication() );
206 aVtkView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
210 // SUIT_ViewManager* aViewManager =
211 // anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
212 // if (aViewManager) {
213 // if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
214 // if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
215 // aViewWindow->raise();
216 // aViewWindow->setFocus();
223 SOCC_ViewWindow* GetActiveOCCViewWindow()
225 SOCC_ViewWindow* anOccView = NULL;
226 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
227 (SUIT_Session::session()->activeApplication());
229 anOccView = dynamic_cast<SOCC_ViewWindow*>(anApp->desktop()->activeWindow());
232 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anApp->desktop()->activeWindow() );
233 std::cout << "aOCCFrame => "<< aOCCFrame;
239 OCCViewer_ViewWindow* GetActiveOCCViewerWindow()
241 OCCViewer_ViewWindow* aOCCFrame = NULL;
242 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
243 (SUIT_Session::session()->activeApplication());
244 if (anApp) aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anApp->desktop()->activeWindow() );
245 std::cout << "aOCCFrame => "<< aOCCFrame;
251 int GetNameOfSelectedNodes( SVTK_ViewWindow *theWindow,
252 const Handle(SALOME_InteractiveObject)& theIO,
255 SVTK_Selector* theSelector = theWindow->GetSelector();
257 TColStd_IndexedMapOfInteger aMapIndex;
258 theSelector->GetIndex(theIO,aMapIndex);
260 for( int i = 1; i <= aMapIndex.Extent(); i++ )
261 theName += QString(" %1").arg(aMapIndex(i));
263 return aMapIndex.Extent();
268 int GetNameOfSelectedElements( SVTK_ViewWindow *theWindow,
269 const Handle(SALOME_InteractiveObject)& theIO,
272 SVTK_Selector* theSelector = theWindow->GetSelector();
276 TColStd_IndexedMapOfInteger aMapIndex;
277 theSelector->GetIndex(theIO,aMapIndex);
279 typedef std::set<int> TIdContainer;
281 std::set<int> anIdContainer;
283 for( int i = 1; i <= aMapIndex.Extent(); i++)
284 anIdContainer.insert(aMapIndex(i));
286 std::set<int>::const_iterator anIter = anIdContainer.begin();
288 for( ; anIter != anIdContainer.end(); anIter++)
289 theName += QString(" %1").arg(*anIter);
291 //std::cout << "GetNameOfSelectedElements name =>" << theName.toStdString() << std::endl;
292 return aMapIndex.Extent();
295 string shape2string( const TopoDS_Shape& aShape )
297 ostringstream streamShape;
299 BRepTools::Write(aShape, streamShape);
300 // BRepTools::Write(aShape, strShape);
302 return streamShape.str();
309 // SALOME_View* LightApp_Displayer::GetActiveView()
311 // SUIT_Session* session = SUIT_Session::session();
312 // if ( SUIT_Application* app = session->activeApplication() ) {
313 // if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
314 // if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
315 // if ( SUIT_ViewModel* vmod = vman->getViewModel() )
316 // return dynamic_cast<SALOME_View*>( vmod );
325 MyGEOM_Displayer::MyGEOM_Displayer( SalomeApp_Study* app ):
326 GEOM_Displayer( app )
330 MyGEOM_Displayer::~MyGEOM_Displayer()
334 SALOME_Prs* MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
336 //std::cout << "MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )" << std::endl;
337 if ( theObj->_is_nil() )
340 SALOME_View* view = NULL;
341 SUIT_ViewManager* vman = HEXABLOCKGUI::currentOccView->getViewManager();
342 SUIT_ViewModel* vmodel = NULL;
344 vmodel = vman->getViewModel();
346 view = dynamic_cast<SALOME_View*>(vmodel);
348 myViewFrame = view ;//GetActiveView();
349 if ( myViewFrame == 0 )
352 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
357 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
358 myType = theObj->GetType();
360 // Update presentation
368 }//namespace HEXABLOCK{
370 //////////////////////////////////////////////////////////////////////////
373 // SUIT_Study* GetActiveStudy();
374 // std::string name( _PTR(SObject) theSO );
375 // std::string name( const std::string& entry );
376 // SVTK_ViewWindow* GetActiveVTKViewWindow();
377 // SOCC_ViewWindow* GetActiveOCCViewWindow();
378 // OCCViewer_ViewWindow* GetActiveOCCViewerWindow();
379 // int GetNameOfSelectedNodes( SVTK_ViewWindow *theWindow,
380 // const Handle(SALOME_InteractiveObject)& theIO,
381 // QString& theName );
383 // QString addInStudy ( GEOM::GEOM_Object_ptr o, const char* theName )
387 // std::cout << "getStudyId() => " << getStudyId() << std::endl;
388 // std::cout << "getStudy() => " << getStudy() << std::endl;
391 // res = GEOMBase_Helper::addInStudy(o, theName);
392 // std::cout << "addInStudy => " << res.toStdString() << std::endl;
398 // // displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
399 // void displayPreview( GEOM::GEOM_Object_ptr obj,
400 // const bool append = false,
401 // const bool activate = false,
402 // const bool update = true,
403 // const double lineWidth = -1,
404 // const int displayMode = -1,
405 // const int color = -1 )
407 // std::cout << "AAAAAAAAAA => " << std::endl;
408 // // GEOM::GEOM_ITransformOperations_var anOp =
409 // // getGeomEngine()->GetITransformOperations(getStudyId());
410 // // GEOM::GEOM_Object_ptr obj2 = anOp->TranslateDXDYDZ (obj, 100, 100, 100);
412 // GEOM::GEOM_IBasicOperations_var anOp =
413 // getGeomEngine()->GetIBasicOperations(getStudyId());
414 // std::cout << "BBBBBBBBBB => " << std::endl;
415 // GEOM::GEOM_Object_ptr obj2 = anOp->MakePointXYZ (100, 125, 150);
417 // std::cout << "obj2->GetEntry() => " << obj2->GetEntry()<< std::endl;
418 // std::cout << "obj2->GetStudyID() => " << obj2->GetStudyID()<< std::endl;
419 // std::cout << "obj2->GetType() => " << obj2->GetType()<< std::endl;
420 // std::cout << "obj2->GetShapeType() => " << obj2->GetShapeType()<< std::endl;
422 // QString res = addInStudy ( obj2, "trans");
423 // std::cout << "trans => " << res.toStdString() << std::endl;
425 // globalSelection(); // close local contexts, if any
426 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
427 // GEOMBase_Helper::activate( 39);//GEOM_MARKER );
429 // // getDisplayer()->SetColor( Quantity_NOC_RED );
430 // // getDisplayer()->SetColor( Quantity_NOC_CYAN1 );
432 // // set width of displayed shape
433 // // getDisplayer()->SetWidth( (lineWidth == -1)?8:lineWidth );
435 // GEOMBase_Helper::displayPreview( obj2,
441 // Quantity_NOC_CYAN1);//Quantity_NOC_RED);//color );
446 // void erase( GEOM::GEOM_Object_ptr obj, const bool d = true)
448 // GEOMBase_Helper::erase( obj, d);
453 // TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
455 // TopoDS_Shape result;
456 // if(IOR.trimmed().isEmpty())
459 // CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
460 // if(CORBA::is_nil(obj))
462 // GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
463 // if (GeomObject->_is_nil())
466 // result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);