1 // Copyright (C) 2009-2013 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"
65 #include "HEXABLOCKGUI_OccGraphicView.hxx"
71 // using namespace HEXABLOCK::GUI;
79 SUIT_Study* GetActiveStudy()
81 SUIT_Application* app = SUIT_Session::session()->activeApplication();
83 return app->activeStudy();
89 _PTR(Study) GetActiveStudyDocument()
91 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
93 return aStudy->studyDS();
99 CORBA::Object_var corbaObj( _PTR(SObject) theSO )
101 //std::cout<< "corbaObj( _PTR(SObject) theSO )" << std::endl;
102 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
104 //std::cout<< "theSO" << std::endl;
105 std::string aValue = theSO->GetIOR();
106 //std::cout<< "aValue" << std::endl;
107 if (strcmp(aValue.c_str(), "") != 0) {
108 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
109 //std::cout<< "anORB" << anORB << std::endl;
110 aCorbaObj = anORB->string_to_object(aValue.c_str());
111 //std::cout<< "aCorbaObj" << aCorbaObj << std::endl;
112 // anDoc = Document::_narrow(aCorbaObj);
115 return aCorbaObj._retn();
119 CORBA::Object_var corbaObj( const Handle(SALOME_InteractiveObject)& theIO )
121 CORBA::Object_var aCorbaObj = CORBA::Object::_nil();
123 if ( !theIO.IsNull() && theIO->hasEntry() ){
124 _PTR(Study) aStudy = GetActiveStudyDocument();
125 _PTR(SObject) aSObj = aStudy->FindObjectID(theIO->getEntry());
126 aCorbaObj = corbaObj(aSObj);
128 return aCorbaObj._retn();
132 std::string name( _PTR(SObject) theSO )
134 std::cout << "name( _PTR(SObject) theSO )"<< theSO;
135 std::string aResName;
138 _PTR(GenericAttribute) anAttr;
139 _PTR(AttributeName) aNameAttr;
140 if ( theSO->FindAttribute( anAttr, "AttributeName" ) )
142 std::cout << "FindAttribute";
144 std::cout << "aNameAttr = anAttr";
145 aResName = aNameAttr->Value().c_str();
152 std::string name( const std::string& entry )
154 std::cout << "name( const std::string& entry )"<< entry;
155 std::string aResName;
157 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
159 std::cout << "appStudy => "<< appStudy ;
160 _PTR(Study) aStudy = appStudy->studyDS();
161 std::cout << "aStudy=> "<< appStudy ;
162 _PTR(SObject) obj( aStudy->FindObjectID( entry ) );
163 std::cout << "obj=> "<< obj;
164 aResName = name( obj );
173 SALOME_Actor* findActorByEntry( SVTK_ViewWindow *theVtkViewWindow, const char* theEntry)
175 // SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
176 SALOME_Actor *foundActor = NULL;
177 vtkActor *aVTKActor = NULL;
178 Handle(SALOME_InteractiveObject) anIO;
180 vtkRenderer *aRenderer = theVtkViewWindow->getRenderer();
181 VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
182 vtkActorCollection *aCollection = aCopy.GetActors();
183 aCollection->InitTraversal();
184 while( aVTKActor = aCollection->GetNextActor() ){
185 // if ( anAct->IsA("GEOM_Actor") ) std::cout<<"is an actor"<< std::endl;
186 foundActor = dynamic_cast<SALOME_Actor*>( aVTKActor );
187 if ( foundActor && foundActor->hasIO() ){
188 anIO = foundActor->getIO();
189 if( anIO->hasEntry() && strcmp(anIO->getEntry(), theEntry) == 0 )
194 return NULL; // no actor found
201 SVTK_ViewWindow* GetActiveVTKViewWindow()
203 SVTK_ViewWindow* aVtkView = NULL;
204 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
205 ( SUIT_Session::session()->activeApplication() );
207 aVtkView = dynamic_cast<SVTK_ViewWindow*>(anApp->desktop()->activeWindow());
211 // SUIT_ViewManager* aViewManager =
212 // anApp->getViewManager(SVTK_Viewer::Type(), createIfNotFound);
213 // if (aViewManager) {
214 // if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
215 // if (SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
216 // aViewWindow->raise();
217 // aViewWindow->setFocus();
224 SOCC_ViewWindow* GetActiveOCCViewWindow()
226 SOCC_ViewWindow* anOccView = NULL;
227 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
228 (SUIT_Session::session()->activeApplication());
230 anOccView = dynamic_cast<SOCC_ViewWindow*>(anApp->desktop()->activeWindow());
233 OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anApp->desktop()->activeWindow() );
234 std::cout << "aOCCFrame => "<< aOCCFrame;
240 OCCViewer_ViewWindow* GetActiveOCCViewerWindow()
242 OCCViewer_ViewWindow* aOCCFrame = NULL;
243 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
244 (SUIT_Session::session()->activeApplication());
245 if (anApp) aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anApp->desktop()->activeWindow() );
246 std::cout << "aOCCFrame => "<< aOCCFrame;
252 int GetNameOfSelectedNodes( SVTK_ViewWindow *theWindow,
253 const Handle(SALOME_InteractiveObject)& theIO,
256 SVTK_Selector* theSelector = theWindow->GetSelector();
258 TColStd_IndexedMapOfInteger aMapIndex;
259 theSelector->GetIndex(theIO,aMapIndex);
261 for( int i = 1; i <= aMapIndex.Extent(); i++ )
262 theName += QString(" %1").arg(aMapIndex(i));
264 return aMapIndex.Extent();
269 int GetNameOfSelectedElements( SVTK_ViewWindow *theWindow,
270 const Handle(SALOME_InteractiveObject)& theIO,
273 SVTK_Selector* theSelector = theWindow->GetSelector();
277 TColStd_IndexedMapOfInteger aMapIndex;
278 theSelector->GetIndex(theIO,aMapIndex);
280 typedef std::set<int> TIdContainer;
282 std::set<int> anIdContainer;
284 for( int i = 1; i <= aMapIndex.Extent(); i++)
285 anIdContainer.insert(aMapIndex(i));
287 std::set<int>::const_iterator anIter = anIdContainer.begin();
289 for( ; anIter != anIdContainer.end(); anIter++)
290 theName += QString(" %1").arg(*anIter);
292 //std::cout << "GetNameOfSelectedElements name =>" << theName.toStdString() << std::endl;
293 return aMapIndex.Extent();
296 string shape2string( const TopoDS_Shape& aShape )
298 ostringstream streamShape;
300 BRepTools::Write(aShape, streamShape);
301 // BRepTools::Write(aShape, strShape);
303 return streamShape.str();
310 // SALOME_View* LightApp_Displayer::GetActiveView()
312 // SUIT_Session* session = SUIT_Session::session();
313 // if ( SUIT_Application* app = session->activeApplication() ) {
314 // if ( LightApp_Application* sApp = dynamic_cast<LightApp_Application*>( app ) ) {
315 // if( SUIT_ViewManager* vman = sApp->activeViewManager() ) {
316 // if ( SUIT_ViewModel* vmod = vman->getViewModel() )
317 // return dynamic_cast<SALOME_View*>( vmod );
326 MyGEOM_Displayer::MyGEOM_Displayer( SalomeApp_Study* app ):
327 GEOM_Displayer( app )
331 MyGEOM_Displayer::~MyGEOM_Displayer()
335 SALOME_Prs* MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
337 //std::cout << "MyGEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )" << std::endl;
338 if ( theObj->_is_nil() )
341 SALOME_View* view = NULL;
343 SUIT_ViewManager* vman = NULL;
344 if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
345 vman = HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager();
347 SUIT_ViewModel* vmodel = NULL;
349 vmodel = vman->getViewModel();
351 view = dynamic_cast<SALOME_View*>(vmodel);
353 myViewFrame = view ;//GetActiveView();
354 if ( myViewFrame == 0 )
357 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
362 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
363 myType = theObj->GetType();
365 // Update presentation
373 }//namespace HEXABLOCK{
375 //////////////////////////////////////////////////////////////////////////
378 // SUIT_Study* GetActiveStudy();
379 // std::string name( _PTR(SObject) theSO );
380 // std::string name( const std::string& entry );
381 // SVTK_ViewWindow* GetActiveVTKViewWindow();
382 // SOCC_ViewWindow* GetActiveOCCViewWindow();
383 // OCCViewer_ViewWindow* GetActiveOCCViewerWindow();
384 // int GetNameOfSelectedNodes( SVTK_ViewWindow *theWindow,
385 // const Handle(SALOME_InteractiveObject)& theIO,
386 // QString& theName );
388 // QString addInStudy ( GEOM::GEOM_Object_ptr o, const char* theName )
392 // std::cout << "getStudyId() => " << getStudyId() << std::endl;
393 // std::cout << "getStudy() => " << getStudy() << std::endl;
396 // res = GEOMBase_Helper::addInStudy(o, theName);
397 // std::cout << "addInStudy => " << res.toStdString() << std::endl;
403 // // displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
404 // void displayPreview( GEOM::GEOM_Object_ptr obj,
405 // const bool append = false,
406 // const bool activate = false,
407 // const bool update = true,
408 // const double lineWidth = -1,
409 // const int displayMode = -1,
410 // const int color = -1 )
412 // std::cout << "AAAAAAAAAA => " << std::endl;
413 // // GEOM::GEOM_ITransformOperations_var anOp =
414 // // getGeomEngine()->GetITransformOperations(getStudyId());
415 // // GEOM::GEOM_Object_ptr obj2 = anOp->TranslateDXDYDZ (obj, 100, 100, 100);
417 // GEOM::GEOM_IBasicOperations_var anOp =
418 // getGeomEngine()->GetIBasicOperations(getStudyId());
419 // std::cout << "BBBBBBBBBB => " << std::endl;
420 // GEOM::GEOM_Object_ptr obj2 = anOp->MakePointXYZ (100, 125, 150);
422 // std::cout << "obj2->GetEntry() => " << obj2->GetEntry()<< std::endl;
423 // std::cout << "obj2->GetStudyID() => " << obj2->GetStudyID()<< std::endl;
424 // std::cout << "obj2->GetType() => " << obj2->GetType()<< std::endl;
425 // std::cout << "obj2->GetShapeType() => " << obj2->GetShapeType()<< std::endl;
427 // QString res = addInStudy ( obj2, "trans");
428 // std::cout << "trans => " << res.toStdString() << std::endl;
430 // globalSelection(); // close local contexts, if any
431 // localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
432 // GEOMBase_Helper::activate( 39);//GEOM_MARKER );
434 // // getDisplayer()->SetColor( Quantity_NOC_RED );
435 // // getDisplayer()->SetColor( Quantity_NOC_CYAN1 );
437 // // set width of displayed shape
438 // // getDisplayer()->SetWidth( (lineWidth == -1)?8:lineWidth );
440 // GEOMBase_Helper::displayPreview( obj2,
446 // Quantity_NOC_CYAN1);//Quantity_NOC_RED);//color );
451 // void erase( GEOM::GEOM_Object_ptr obj, const bool d = true)
453 // GEOMBase_Helper::erase( obj, d);
458 // TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
460 // TopoDS_Shape result;
461 // if(IOR.trimmed().isEmpty())
464 // CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
465 // if(CORBA::is_nil(obj))
467 // GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
468 // if (GeomObject->_is_nil())
471 // result = GEOM_Client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);