1 // Copyright (C) 2007-2010 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
29 #include <GeometryGUI.h>
30 #include <GEOM_Client.hxx>
33 #include <GEOM_Actor.h>
34 #include <SVTK_ViewModel.h>
35 #include <SVTK_ViewWindow.h>
36 #include <OCCViewer_ViewPort3d.h>
37 #include <OCCViewer_ViewModel.h>
38 #include <OCCViewer_ViewWindow.h>
40 #include <SALOME_ListIO.hxx>
41 #include <SALOME_ListIteratorOfListIO.hxx>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_ViewManager.h>
46 #include <SUIT_ViewWindow.h>
47 #include <SUIT_MessageBox.h>
48 #include <SalomeApp_Application.h>
49 #include <SalomeApp_Study.h>
51 // // Open CASCADE Includes
52 #include <BRep_Tool.hxx>
53 #include <BRepAdaptor_Curve.hxx>
54 #include <BRepAdaptor_Surface.hxx>
55 #include <BRepPrimAPI_MakeCone.hxx>
57 #include <AIS_ListIteratorOfListOfInteractive.hxx>
58 #include <AIS_ListOfInteractive.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <Precision.hxx>
67 #include <vtkRenderer.h>
71 //=====================================================================================
72 // function : GetShapeFromIOR()
73 // purpose : Get shape data by the specified IOR
74 //=====================================================================================
75 TopoDS_Shape GEOMBase::GetShapeFromIOR( const QString& IOR )
77 GEOM::GEOM_Object_var geomObj = GEOMBase::GetObjectFromIOR( IOR );
79 GetShape( geomObj, shape, TopAbs_SHAPE );
84 //=====================================================================================
85 // function : GetIndex()
86 // purpose : Get the index of a sub shape in a main shape : index start at 1
87 //=====================================================================================
88 int GEOMBase::GetIndex( const TopoDS_Shape& subshape, const TopoDS_Shape& shape )
91 if ( !shape.IsNull() && !subshape.IsNull() ) {
92 TopTools_IndexedMapOfShape anIndices;
93 TopExp::MapShapes( shape, anIndices );
94 if ( anIndices.Contains( subshape ) )
95 idx = anIndices.FindIndex( subshape );
101 //=======================================================================
102 // function : GetTopoFromSelection()
103 // purpose : Define tds from a single selection and retuen true
104 //=======================================================================
105 TopoDS_Shape GEOMBase::GetTopoFromSelection( const SALOME_ListIO& IObjects )
108 if ( IObjects.Extent() == 1 ){
109 Handle(SALOME_InteractiveObject) IO = IObjects.First();
110 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
111 if ( IO->hasEntry() && study ) {
112 _PTR(Study) studyDS = study->studyDS();
113 _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) );
114 _PTR(GenericAttribute) anAttr;
115 if ( obj && obj->FindAttribute( anAttr, "AttributeIOR" ) ) {
116 _PTR(AttributeIOR) anIOR( anAttr );
117 shape = GetShapeFromIOR( anIOR->Value().c_str() );
124 //=======================================================================
125 // function : GetNameOfSelectedIObjects()
126 // purpose : Define the name geom++ or other name of mono or multi sel.
127 //=======================================================================
128 int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& IObjects,
130 const bool shapesOnly )
133 name = ""; // clear output name
136 nbSel = IObjects.Extent();
138 Handle(SALOME_InteractiveObject) anIObj = IObjects.First();
139 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
140 if ( anIObj->hasEntry() && study ) {
141 _PTR(Study) studyDS = study->studyDS();
142 _PTR(SObject) obj( studyDS->FindObjectID( anIObj->getEntry() ) );
143 _PTR(GenericAttribute) anAttr;
144 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
145 _PTR(AttributeName) aNameAttr ( anAttr );
146 name = aNameAttr->Value().c_str();
152 GEOM::ListOfGO anObjs;
153 ConvertListOfIOInListOfGO( IObjects, anObjs, shapesOnly );
154 nbSel = anObjs.length();
156 name = GetName( anObjs[ 0 ] );
160 name = QObject::tr( "%1_objects" ).arg( nbSel );
166 //=================================================================================
167 // function : GetShapeTypeString()
168 // purpose : for a single shape
169 //=================================================================================
170 QString GEOMBase::GetShapeTypeString(const TopoDS_Shape& shape)
173 if ( !shape.IsNull() ) {
174 switch ( shape.ShapeType() ) {
175 case TopAbs_COMPOUND:
177 aTypeString = QObject::tr( "GEOM_COMPOUND" );
180 case TopAbs_COMPSOLID:
182 aTypeString = QObject::tr( "GEOM_COMPOUNDSOLID" );
187 aTypeString = QObject::tr( "GEOM_SOLID" );
192 aTypeString = QObject::tr( "GEOM_SHELL" );
197 BRepAdaptor_Surface surf( TopoDS::Face( shape ) );
198 switch ( surf.GetType() ) {
201 aTypeString = QObject::tr( "GEOM_PLANE" );
204 case GeomAbs_Cylinder:
206 aTypeString = QObject::tr( "GEOM_SURFCYLINDER" );
211 aTypeString = QObject::tr( "GEOM_SURFSPHERE" );
216 aTypeString = QObject::tr( "GEOM_SURFTORUS" );
221 aTypeString = QObject::tr( "GEOM_SURFCONE" );
226 aTypeString = QObject::tr( "GEOM_FACE" );
234 aTypeString = QObject::tr( "GEOM_WIRE" );
239 BRepAdaptor_Curve curv( TopoDS::Edge( shape ) );
240 switch ( curv.GetType() ) {
243 aTypeString = ( qAbs( curv.FirstParameter() ) >= 1E6 || qAbs( curv.LastParameter() ) >= 1E6 ) ?
244 QObject::tr( "GEOM_LINE" ) : QObject::tr( "GEOM_EDGE" );
249 aTypeString = curv.IsClosed() ? QObject::tr( "GEOM_CIRCLE" ) : QObject::tr( "GEOM_ARC" );
254 aTypeString = QObject::tr( "GEOM_EDGE" );
262 aTypeString = QObject::tr( "GEOM_VERTEX" );
267 aTypeString = QObject::tr( "GEOM_SHAPE" );
280 //=======================================================================
281 // function : ConvertIORinGEOMAISShape()
283 //=======================================================================
284 Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const QString& IOR, bool onlyInActiveView)
286 Handle(GEOM_AISShape) shape;
288 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
290 _PTR(Study) studyDS = study->studyDS();
291 _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
293 QList<SUIT_ViewWindow*> views;
294 if ( onlyInActiveView )
295 views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
297 views = SUIT_Session::session()->activeApplication()->desktop()->windows();
298 foreach ( SUIT_ViewWindow* view, views ) {
299 if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
300 Handle(AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext();
302 AIS_ListOfInteractive displayed;
303 ic->DisplayedObjects( displayed );
304 ic->ObjectsInCollector( displayed );
306 AIS_ListIteratorOfListOfInteractive it( displayed );
307 while ( it.More() && shape.IsNull() ) {
308 if ( it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
309 Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
310 if ( !sh.IsNull() && sh->hasIO() ) {
311 Handle(SALOME_InteractiveObject) IO = Handle(SALOME_InteractiveObject)::DownCast( sh->getIO() );
312 if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() )
319 if ( !shape.IsNull() ) break;
327 //=======================================================================
328 // function : ConvertIORinGEOMActor()
330 //=======================================================================
331 GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const QString& IOR, bool onlyInActiveView)
333 GEOM_Actor* actor = 0;
335 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
337 _PTR(Study) studyDS = study->studyDS();
338 _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
340 QList<SUIT_ViewWindow*> views;
341 if ( onlyInActiveView )
342 views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
344 views = SUIT_Session::session()->activeApplication()->desktop()->windows();
345 foreach ( SUIT_ViewWindow* view, views ) {
346 if ( view && view->getViewManager()->getType() == SVTK_Viewer::Type() ) {
347 SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( view );
348 if( !aVTKViewWindow )
350 vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
351 vtkActorCollection* theActors = Renderer->GetActors();
352 theActors->InitTraversal();
353 vtkActor* a = theActors->GetNextActor();
354 while( a && !actor ) {
355 if ( a->IsA( "GEOM_Actor" ) ) {
356 GEOM_Actor* ga = GEOM_Actor::SafeDownCast( a );
357 if ( ga && ga->hasIO() ) {
358 Handle(SALOME_InteractiveObject) IO = Handle(SALOME_InteractiveObject)::DownCast( ga->getIO() );
359 if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() )
363 a = theActors->GetNextActor();
373 //=======================================================================
374 // function : GetAIS()
376 //=======================================================================
377 Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& IO,
378 bool onlyInActiveView, bool onlyGeom )
380 Handle(AIS_InteractiveObject) aisObject;
382 if ( !IO.IsNull() && IO->hasEntry() ) {
383 QList<SUIT_ViewWindow*> views;
384 if ( onlyInActiveView )
385 views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
387 views = SUIT_Session::session()->activeApplication()->desktop()->windows();
389 foreach ( SUIT_ViewWindow* view, views ) {
390 if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
391 Handle(AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext();
393 AIS_ListOfInteractive displayed;
394 anIC->DisplayedObjects( displayed );
395 anIC->ObjectsInCollector( displayed );
397 AIS_ListIteratorOfListOfInteractive it( displayed );
398 for ( ; it.More(); it.Next() ){
399 if ( onlyGeom && !it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) )
402 Handle(SALOME_InteractiveObject) obj =
403 Handle(SALOME_InteractiveObject)::DownCast( it.Value()->GetOwner() );
405 if ( !obj.IsNull() && obj->isSame( IO ) )
407 aisObject = it.Value();
412 if ( !aisObject.IsNull() ) break;
420 //=======================================================================
421 // function : ConvertIOinGEOMAISShape()
423 //=======================================================================
424 Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, bool onlyInActiveView )
426 return Handle(GEOM_AISShape)::DownCast( GetAIS( IO, onlyInActiveView, true ) );
430 //=======================================================================
431 // function : ConvertListOfIOInListOfIOR()
433 //=======================================================================
434 QStringList GEOMBase::ConvertListOfIOInListOfIOR( const SALOME_ListIO& IObjects )
437 SALOME_ListIteratorOfListIO it( IObjects );
438 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
440 _PTR(Study) studyDS = study->studyDS();
441 for ( ; it.More(); it.Next() ) {
442 GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() );
443 if ( !CORBA::is_nil( geomObj ) )
444 iors.append( GetIORFromObject( geomObj ) );
451 //=======================================================================
452 // function : ConvertIOinGEOMObject()
454 //=======================================================================
455 GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& IO )
457 GEOM::GEOM_Object_var object;
459 if ( !IO.IsNull() && IO->hasEntry() ) {
460 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
462 _PTR(Study) studyDS = study->studyDS();
463 _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) );
465 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
466 if ( !CORBA::is_nil( corbaObj ) )
467 object = GEOM::GEOM_Object::_narrow( corbaObj );
471 return object._retn();
475 //=======================================================================
476 // function : ConvertListOfIOInListOfGO()
478 //=======================================================================
479 void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& IObjects,
480 GEOM::ListOfGO& geomObjects,
483 geomObjects.length( 0 );
485 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
487 _PTR(Study) studyDS = study->studyDS();
489 geomObjects.length( IObjects.Extent() );
490 SALOME_ListIteratorOfListIO it( IObjects );
493 for ( ; it.More(); it.Next() ) {
494 GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() );
495 if ( !CORBA::is_nil( geomObj ) && ( !shapesOnly || IsShape( geomObj ) ) )
496 geomObjects[ i++ ] = geomObj;
498 geomObjects.length( i );
503 //=================================================================================
504 // function : CreateArrowForLinearEdge()
505 // purpose : Create a cone topology to be used to display an arrow in the middle
506 // : of an edge showing its orientation. (For simulation and Viewer OCC only)
507 //=================================================================================
508 TopoDS_Shape GEOMBase::CreateArrowForLinearEdge( const TopoDS_Shape& shape )
510 TopoDS_Shape ArrowCone;
512 SUIT_ViewWindow* view = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
513 if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() && shape.ShapeType() == TopAbs_EDGE ) {
514 Handle(V3d_View) view3d = ((OCCViewer_ViewWindow*)view)->getViewPort()->getView();
515 Standard_Real Width, Height;
516 view3d->Size( Width, Height );
517 const Standard_Real aHeight = (Width + Height) / 50.0;
520 Standard_Real first, last;
521 Handle(Geom_Curve) curv = BRep_Tool::Curve( TopoDS::Edge( shape ), first, last );
522 if ( curv->IsCN(1) ) {
523 const Standard_Real param = ( first+last ) / 2.0;
524 gp_Pnt middleParamPoint;
526 curv->D1( param, middleParamPoint, V1 );
527 if ( V1.Magnitude() > Precision::Confusion() ) {
528 /* Topology orientation not geom orientation */
529 if ( shape.Orientation() == TopAbs_REVERSED )
532 gp_Ax2 anAxis( middleParamPoint, gp_Dir( V1 ) );
533 const Standard_Real radius1 = aHeight / 5.0;
534 if ( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() )
535 ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
539 catch ( Standard_Failure ) {
540 // OCC failures are hard to catch in GUI.
541 // This is because of the position for #include <Standard_ErrorHandler.hxx> that is very critical to find
542 // in SALOME environment : compilation error !
550 //=================================================================================
551 // function : VertexToPoint()
552 // purpose : If S can be converted in a gp_Pnt returns true and the result is P
553 //=================================================================================
554 bool GEOMBase::VertexToPoint( const TopoDS_Shape& shape, gp_Pnt& point )
556 if ( shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX )
558 point = BRep_Tool::Pnt( TopoDS::Vertex( shape ) );
563 //=================================================================================
564 // function : GetBipointDxDyDz()
566 //=================================================================================
567 void GEOMBase::GetBipointDxDyDz( const gp_Pnt& point1, const gp_Pnt& point2, double& dx, double& dy, double& dz )
569 dx = point2.X() - point1.X();
570 dy = point2.Y() - point1.Y();
571 dz = point2.Z() - point1.Z();
575 //=================================================================================
576 // function : LinearEdgeExtremities()
577 // purpose : If S can be converted in a linear edge and if initial an final points
578 // : distance is sufficient, returns true else returns false.
579 // : Resulting points are respectively P1 and P2
580 //=================================================================================
581 bool GEOMBase::LinearEdgeExtremities( const TopoDS_Shape& shape, gp_Pnt& point1, gp_Pnt& point2 )
583 if ( shape.IsNull() || shape.ShapeType() != TopAbs_EDGE )
586 BRepAdaptor_Curve curv( TopoDS::Edge( shape ) );
587 if ( curv.GetType() != GeomAbs_Line )
592 curv.D0( curv.FirstParameter(), p1 );
593 curv.D0( curv.LastParameter(), p2 );
595 if ( p1.Distance( p2 ) <= Precision::Confusion() )
604 //=======================================================================
605 // function : SelectionByNameInDialogs()
606 // purpose : Called when user has entered a name of object in a LineEdit.
607 // : The selection is changed. Dialog box will receive the
608 // : corresponding signal to manage this event.
609 //=======================================================================
610 bool GEOMBase::SelectionByNameInDialogs( QWidget* widget, const QString& objectUserName, const SALOME_ListIO& /*IObjects*/ )
612 /* Find SObject with name in component GEOM */
613 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
614 if ( !study ) return false;
615 _PTR(Study) studyDS = study->studyDS();
617 std::vector<_PTR(SObject)> listSO = studyDS->FindObjectByName( objectUserName.toStdString(), "GEOM" );
619 if ( listSO.size() < 1 ) {
620 SUIT_MessageBox::critical( widget,
621 QObject::tr( "GEOM_WRN_WARNING" ),
622 QObject::tr( "GEOM_NAME_INCORRECT" ),
623 QObject::tr( "GEOM_BUT_OK" ) );
627 /* More than one object with same name */
628 if ( listSO.size() > 1 ) {
629 SUIT_MessageBox::critical( widget,
630 QObject::tr("GEOM_WRN_WARNING"),
631 QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"),
632 QObject::tr("GEOM_BUT_OK") );
636 /* Create a SALOME_InteractiveObject with a SALOME::SObject */
637 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject( listSO[0]->GetID().c_str(),
639 objectUserName.toLatin1().constData() );
641 /* Add as a selected object */
642 /* Clear any previous selection : */
643 /* Warning the LineEdit is purged because of signal currentSelectionChanged ! */
644 // Sel->ClearIObjects(); //mzn
645 // Sel->AddIObject(SI); //mzn
650 //=======================================================================
651 // function : DefineDlgPosition()
652 // purpose : Define x and y the default position for a dialog box
653 //=======================================================================
654 void GEOMBase::DefineDlgPosition( QWidget* dlg, int& x, int& y )
656 /* Here the position is on the bottom right corner - 10 */
657 SUIT_Desktop* d = SUIT_Session::session()->activeApplication()->desktop();
658 x = abs( d->x() + d->size().width() - dlg->size().width() - 10 );
659 y = abs( d->y() + d->size().height() - dlg->size().height() - 10 );
663 //=======================================================================
664 // function : GetDefaultName()
665 // purpose : Generates default names
666 //=======================================================================
667 QString GEOMBase::GetDefaultName( const QString& operation, bool extractPrefix )
671 // collect all object names of GEOM component
672 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
674 _PTR(Study) studyDS = study->studyDS();
676 std::set<std::string> names;
677 _PTR(SComponent) component( studyDS->FindComponent( "GEOM" ) );
679 _PTR(ChildIterator) it( studyDS->NewChildIterator( component ) );
680 for ( it->InitEx( true ); it->More(); it->Next() ) {
681 names.insert( it->Value()->GetName() );
685 // build a unique name
687 bool isUnique = false;
688 QString prefix = operation;
690 if ( extractPrefix ) {
691 QStringList parts = prefix.split( "_", QString::KeepEmptyParts );
692 if ( parts.count() > 1 ) {
694 aNumber = parts.last().toLong( &ok );
697 prefix = parts.join( "_" );
703 while ( !isUnique ) {
704 aName = prefix + "_" + QString::number( ++aNumber );
705 isUnique = ( names.count( aName.toStdString()) == 0 );
712 //=======================================================================
713 // function : ShowErrorMessage()
714 // purpose : Shows message box with error code and comment
715 //=======================================================================
716 void GEOMBase::ShowErrorMessage( const QString& errorCode, const QString& comment )
719 text << QObject::tr( "GEOM_PRP_ABORT" );
720 if ( !errorCode.isEmpty() )
721 text << QObject::tr( errorCode.toLatin1().constData() );
722 if ( !comment.isEmpty() )
723 text << QObject::tr( comment.toLatin1().constData() );
725 SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
726 QObject::tr( "GEOM_ERROR" ),
728 QObject::tr( "GEOM_BUT_OK" ) );
732 //=======================================================================
733 // function : GetObjectFromIOR()
734 // purpose : returns a GEOM_Object by given IOR (string)
735 //=======================================================================
736 GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR )
738 GEOM::GEOM_Object_var geomObj;
739 if ( !IOR.isEmpty() ) {
740 CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object( IOR.toLatin1().constData() );
741 if ( !CORBA::is_nil( corbaObj ) )
742 geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
744 return geomObj._retn();
747 //=======================================================================
748 // function : GetIORFromObject()
749 // purpose : returns IOR of a given GEOM_Object
750 //=======================================================================
751 QString GEOMBase::GetIORFromObject( GEOM::GEOM_Object_ptr object )
754 if ( !CORBA::is_nil( object ) ) {
755 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( object );
761 //=======================================================================
762 // function : GetShape()
763 // purpose : returns a TopoDS_Shape stored in GEOM_Object
764 //=======================================================================
765 bool GEOMBase::GetShape( GEOM::GEOM_Object_ptr object, TopoDS_Shape& shape, const TopAbs_ShapeEnum type )
767 shape = TopoDS_Shape();
768 if ( !CORBA::is_nil( object ) ) {
769 TopAbs_ShapeEnum stype = (TopAbs_ShapeEnum)( object->GetShapeType() );
770 if ( type == TopAbs_SHAPE || type == stype )
771 shape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), object );
773 return !shape.IsNull();
776 //=======================================================================
777 // function : GetName()
778 // purpose : Get name of object
779 //=======================================================================
780 QString GEOMBase::GetName( GEOM::GEOM_Object_ptr object )
783 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
784 CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object );
785 if ( study && strcmp( IOR.in(), "" ) != 0 ) {
786 _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) );
787 _PTR(GenericAttribute) anAttr;
788 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) {
789 _PTR(AttributeName) aNameAttr( anAttr );
790 name = aNameAttr->Value().c_str();
797 //=======================================================================
798 // function : IsShape()
799 // purpose : Return TRUE if object is valid and has shape
800 //=======================================================================
801 bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr object )
803 return !object->_is_nil() && object->IsShape();