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();
274 TColStd_IndexedMapOfInteger aMapIndex;
275 theSelector->GetIndex(theIO,aMapIndex);
277 typedef std::set<int> TIdContainer;
278 std::set<int> anIdContainer;
279 for( int i = 1; i <= aMapIndex.Extent(); i++)
280 anIdContainer.insert(aMapIndex(i));
282 std::set<int>::const_iterator anIter = anIdContainer.begin();
283 for( ; anIter != anIdContainer.end(); anIter++)
284 theName += QString(" %1").arg(*anIter);
286 //std::cout << "GetNameOfSelectedElements name =>" << theName.toStdString() << std::endl;
287 return aMapIndex.Extent();
290 string shape2string( const TopoDS_Shape& aShape )
292 ostringstream streamShape;
294 BRepTools::Write(aShape, streamShape);
295 // BRepTools::Write(aShape, strShape);
297 return streamShape.str();
304 // SALOME_View* LightApp_Displayer::GetActiveView()
306 // SUIT_Session* session = SUIT_Session::session();
307 // if ( SUIT_Application* app = session->activeApplication() ) {
308 // if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
309 // if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
310 // if ( SUIT_ViewModel* vmod = vman->getViewModel() )
311 // return dynamic_cast<SALOME_View*>( vmod );
320 MyGEOM_Displayer::MyGEOM_Displayer( SalomeApp_Study* app ):
321 GEOM_Displayer( app )
325 MyGEOM_Displayer::~MyGEOM_Displayer()
329 SALOME_Prs* MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
331 //std::cout << "MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )" << std::endl;
332 if ( theObj->_is_nil() )
335 SALOME_View* view = NULL;
336 SUIT_ViewManager* vman = HEXABLOCKGUI::currentOccView->getViewManager();
337 SUIT_ViewModel* vmodel = NULL;
339 vmodel = vman->getViewModel();
341 view = dynamic_cast<SALOME_View*>(vmodel);
343 myViewFrame = view ;//GetActiveView();
344 if ( myViewFrame == 0 )
347 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
352 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
353 myType = theObj->GetType();
355 // Update presentation
363 }//namespace HEXABLOCK{
365 //////////////////////////////////////////////////////////////////////////
368 // SUIT_Study* GetActiveStudy();
369 // std::string name( _PTR(SObject) theSO );
370 // std::string name( const std::string& entry );
371 // SVTK_ViewWindow* GetActiveVTKViewWindow();
372 // SOCC_ViewWindow* GetActiveOCCViewWindow();
373 // OCCViewer_ViewWindow* GetActiveOCCViewerWindow();
374 // int GetNameOfSelectedNodes( SVTK_ViewWindow *theWindow,
375 // const Handle(SALOME_InteractiveObject)& theIO,
376 // QString& theName );
378 // QString addInStudy ( GEOM::GEOM_Object_ptr o, const char* theName )
382 // std::cout << "getStudyId() => " << getStudyId() << std::endl;
383 // std::cout << "getStudy() => " << getStudy() << std::endl;
386 // res = GEOMBase_Helper::addInStudy(o, theName);
387 // std::cout << "addInStudy => " << res.toStdString() << std::endl;
393 // // displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
394 // void displayPreview( GEOM::GEOM_Object_ptr obj,
395 // const bool append = false,
396 // const bool activate = false,
397 // const bool update = true,
398 // const double lineWidth = -1,
399 // const int displayMode = -1,
400 // const int color = -1 )
402 // std::cout << "AAAAAAAAAA => " << std::endl;
403 // // GEOM::GEOM_ITransformOperations_var anOp =
404 // // getGeomEngine()->GetITransformOperations(getStudyId());
405 // // GEOM::GEOM_Object_ptr obj2 = anOp->TranslateDXDYDZ (obj, 100, 100, 100);
407 // GEOM::GEOM_IBasicOperations_var anOp =
408 // getGeomEngine()->GetIBasicOperations(getStudyId());
409 // std::cout << "BBBBBBBBBB => " << std::endl;
410 // GEOM::GEOM_Object_ptr obj2 = anOp->MakePointXYZ (100, 125, 150);
412 // std::cout << "obj2->GetEntry() => " << obj2->GetEntry()<< std::endl;
413 // std::cout << "obj2->GetStudyID() => " << obj2->GetStudyID()<< std::endl;
414 // std::cout << "obj2->GetType() => " << obj2->GetType()<< std::endl;
415 // std::cout << "obj2->GetShapeType() => " << obj2->GetShapeType()<< std::endl;
417 // QString res = addInStudy ( obj2, "trans");
418 // std::cout << "trans => " << res.toStdString() << std::endl;
420 // globalSelection(); // close local contexts, if any
421 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
422 // GEOMBase_Helper::activate( 39);//GEOM_MARKER );
424 // // getDisplayer()->SetColor( Quantity_NOC_RED );
425 // // getDisplayer()->SetColor( Quantity_NOC_CYAN1 );
427 // // set width of displayed shape
428 // // getDisplayer()->SetWidth( (lineWidth == -1)?8:lineWidth );
430 // GEOMBase_Helper::displayPreview( obj2,
436 // Quantity_NOC_CYAN1);//Quantity_NOC_RED);//color );
441 // void erase( GEOM::GEOM_Object_ptr obj, const bool d = true)
443 // GEOMBase_Helper::erase( obj, d);
448 // TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
450 // TopoDS_Shape result;
451 // if(IOR.trimmed().isEmpty())
454 // CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
455 // if(CORBA::is_nil(obj))
457 // GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
458 // if (GeomObject->_is_nil())
461 // result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);