//=====================================================================================
// function : GetShapeFromIOR()
-// purpose : exist also as static method !
+// purpose : Get shape data by the specified IOR
//=====================================================================================
-TopoDS_Shape GEOMBase::GetShapeFromIOR(QString IOR)
+TopoDS_Shape GEOMBase::GetShapeFromIOR( const QString& IOR )
{
- TopoDS_Shape result;
- if(IOR.trimmed().isEmpty())
- return result;
-
- CORBA::Object_var obj = SalomeApp_Application::orb()->string_to_object(IOR.toLatin1().data());
- if(CORBA::is_nil(obj))
- return result;
- GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( obj );
- if (GeomObject->_is_nil())
- return result;
-
- result = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), GeomObject);
- return result;
+ GEOM::GEOM_Object_var geomObj = GEOMBase::GetObjectFromIOR( IOR );
+ TopoDS_Shape shape;
+ GetShape( geomObj, shape, TopAbs_SHAPE );
+ return shape;
}
// function : GetIndex()
// purpose : Get the index of a sub shape in a main shape : index start at 1
//=====================================================================================
-int GEOMBase::GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int /*ShapeType*/)
+int GEOMBase::GetIndex( const TopoDS_Shape& subshape, const TopoDS_Shape& shape )
{
- if(shape.IsNull() || subshape.IsNull())
- return -1;
-
- TopTools_IndexedMapOfShape anIndices;
- TopExp::MapShapes(shape, anIndices);
- if(anIndices.Contains(subshape)) return anIndices.FindIndex(subshape);
-
- return -1;
+ int idx = -1;
+ if ( !shape.IsNull() && !subshape.IsNull() ) {
+ TopTools_IndexedMapOfShape anIndices;
+ TopExp::MapShapes( shape, anIndices );
+ if ( anIndices.Contains( subshape ) )
+ idx = anIndices.FindIndex( subshape );
+ }
+ return idx;
}
// function : GetTopoFromSelection()
// purpose : Define tds from a single selection and retuen true
//=======================================================================
-bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& tds)
+TopoDS_Shape GEOMBase::GetTopoFromSelection( const SALOME_ListIO& IObjects )
{
- if(aList.Extent() != 1)
- return false;
-
- Handle(SALOME_InteractiveObject) IO = aList.First();
- /* case SObject */
- if(IO->hasEntry()) {
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return false;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
- _PTR(GenericAttribute) anAttr;
- if( obj ) {
- if(obj->FindAttribute(anAttr, "AttributeIOR")) {
- _PTR(AttributeIOR) anIOR ( anAttr );
- tds = GetShapeFromIOR(anIOR->Value().c_str());
- if(tds.IsNull())
- return false;
- else
- return true;
+ TopoDS_Shape shape;
+ if ( IObjects.Extent() == 1 ){
+ Handle(SALOME_InteractiveObject) IO = IObjects.First();
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( IO->hasEntry() && study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) );
+ _PTR(GenericAttribute) anAttr;
+ if ( obj && obj->FindAttribute( anAttr, "AttributeIOR" ) ) {
+ _PTR(AttributeIOR) anIOR( anAttr );
+ shape = GetShapeFromIOR( anIOR->Value().c_str() );
}
}
}
-
- return false;
+ return shape;
}
//=======================================================================
// function : GetNameOfSelectedIObjects()
// purpose : Define the name geom++ or other name of mono or multi sel.
//=======================================================================
-int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
- QString& theName,
- const bool theShapesOnly )
+int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& IObjects,
+ QString& name,
+ const bool shapesOnly )
{
- if ( !theShapesOnly )
- {
- int nbSel = aList.Extent();
- if ( nbSel == 1 )
- {
- Handle(SALOME_InteractiveObject) anIObj = aList.First();
- if(anIObj->hasEntry()) {
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return nbSel;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
-
- _PTR(GenericAttribute) anAttr;
-
- if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
- {
- _PTR(AttributeName) aNameAttr ( anAttr );
- theName = aNameAttr->Value().c_str();
- }
- }
- }
- else
- theName = QObject::tr("%1_objects").arg(nbSel);
-
- return nbSel;
- }
- else
- {
- GEOM::ListOfGO anObjs;
- ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
- if ( anObjs.length() == 1 ) {
- theName = GetName( anObjs[ 0 ] );
+ int nbSel = 0;
+ name = ""; // clear output name
+
+ if ( !shapesOnly ) {
+ nbSel = IObjects.Extent();
+ if ( nbSel == 1 ) {
+ Handle(SALOME_InteractiveObject) anIObj = IObjects.First();
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( anIObj->hasEntry() && study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ _PTR(SObject) obj( studyDS->FindObjectID( anIObj->getEntry() ) );
+ _PTR(GenericAttribute) anAttr;
+ if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
+ _PTR(AttributeName) aNameAttr ( anAttr );
+ name = aNameAttr->Value().c_str();
+ }
}
- else
- theName = QString( "%1_objects" ).arg( anObjs.length() );
-
- return anObjs.length();
}
+ }
+ else {
+ GEOM::ListOfGO anObjs;
+ ConvertListOfIOInListOfGO( IObjects, anObjs, shapesOnly );
+ nbSel = anObjs.length();
+ if ( nbSel == 1 )
+ name = GetName( anObjs[ 0 ] );
+ }
+
+ if ( nbSel > 1 )
+ name = QObject::tr( "%1_objects" ).arg( nbSel );
+
+ return nbSel;
}
// function : GetShapeTypeString()
// purpose : for a single shape
//=================================================================================
-bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString& aTypeString)
+QString GEOMBase::GetShapeTypeString(const TopoDS_Shape& shape)
{
- if(aShape.IsNull()) {
- aTypeString = "aNullShape";
- return false;
- }
- switch(aShape.ShapeType())
- {
+ QString aTypeString;
+ if ( !shape.IsNull() ) {
+ switch ( shape.ShapeType() ) {
case TopAbs_COMPOUND:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData());
- return true;
+ aTypeString = QObject::tr( "GEOM_COMPOUND" );
+ break;
}
- case TopAbs_COMPSOLID:
+ case TopAbs_COMPSOLID:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ;
- return true ;
+ aTypeString = QObject::tr( "GEOM_COMPOUNDSOLID" );
+ break;
}
case TopAbs_SOLID:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ;
- return true ;
+ aTypeString = QObject::tr( "GEOM_SOLID" );
+ break;
}
case TopAbs_SHELL:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ;
- return true ;
+ aTypeString = QObject::tr( "GEOM_SHELL" );
+ break;
}
case TopAbs_FACE:
{
- BRepAdaptor_Surface surf(TopoDS::Face(aShape));
- if(surf.GetType() == GeomAbs_Plane) {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData());
- return true;
- }
- else if(surf.GetType() == GeomAbs_Cylinder) {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData());
- return true;
- }
- else if(surf.GetType() == GeomAbs_Sphere) {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData());
- return true ;
- }
- else if(surf.GetType() == GeomAbs_Torus) {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData());
- return true ;
- }
- else if(surf.GetType() == GeomAbs_Cone) {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData());
- return true ;
- }
- else {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData());
- return true;
- }
+ BRepAdaptor_Surface surf( TopoDS::Face( shape ) );
+ switch ( surf.GetType() ) {
+ case GeomAbs_Plane:
+ {
+ aTypeString = QObject::tr( "GEOM_PLANE" );
+ break;
+ }
+ case GeomAbs_Cylinder:
+ {
+ aTypeString = QObject::tr( "GEOM_SURFCYLINDER" );
+ break;
+ }
+ case GeomAbs_Sphere:
+ {
+ aTypeString = QObject::tr( "GEOM_SURFSPHERE" );
+ break;
+ }
+ case GeomAbs_Torus:
+ {
+ aTypeString = QObject::tr( "GEOM_SURFTORUS" );
+ break;
+ }
+ case GeomAbs_Cone:
+ {
+ aTypeString = QObject::tr( "GEOM_SURFCONE" );
+ break;
+ }
+ default:
+ {
+ aTypeString = QObject::tr( "GEOM_FACE" );
+ break;
+ }
+ }
+ break;
}
case TopAbs_WIRE:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData());
- return true;
+ aTypeString = QObject::tr( "GEOM_WIRE" );
+ break;
}
case TopAbs_EDGE:
{
- BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
- if(curv.GetType() == GeomAbs_Line) {
- if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData());
- else
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
- return true;
- }
- else if(curv.GetType() == GeomAbs_Circle) {
- if(curv.IsClosed())
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData());
- else
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData());
- return true;
- }
- else {
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
- return true;
- }
+ BRepAdaptor_Curve curv( TopoDS::Edge( shape ) );
+ switch ( curv.GetType() ) {
+ case GeomAbs_Line:
+ {
+ aTypeString = ( qAbs( curv.FirstParameter() ) >= 1E6 || qAbs( curv.LastParameter() ) >= 1E6 ) ?
+ QObject::tr( "GEOM_LINE" ) : QObject::tr( "GEOM_EDGE" );
+ break;
+ }
+ case GeomAbs_Circle:
+ {
+ aTypeString = curv.IsClosed() ? QObject::tr( "GEOM_CIRCLE" ) : QObject::tr( "GEOM_ARC" );
+ break;
+ }
+ default:
+ {
+ aTypeString = QObject::tr( "GEOM_EDGE" );
+ break;
+ }
+ }
+ break;
}
case TopAbs_VERTEX:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData());
- return true;
+ aTypeString = QObject::tr( "GEOM_VERTEX" );
+ break;
}
case TopAbs_SHAPE:
{
- aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData());
- return true;
+ aTypeString = QObject::tr( "GEOM_SHAPE" );
+ break;
+ }
+ default:
+ {
+ break;
}
}
- return false;
+ }
+ return aTypeString;
}
// function : ConvertIORinGEOMAISShape()
// purpose :
//=======================================================================
-Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Standard_Boolean& testResult, bool onlyInActiveView)
+Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const QString& IOR, bool onlyInActiveView)
{
- Handle(GEOM_AISShape) resultShape;
- testResult = false;
-
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return resultShape;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
- if ( !anObj )
- return resultShape;
-
- QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
-
- QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
- while ( it.hasNext() ) {
- SUIT_ViewWindow* aVW = it.next();
- if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
- Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
-
- AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
- AIS_ListOfInteractive List1;
- ic->ObjectsInCollector(List1);
- List.Append(List1);
-
- AIS_ListIteratorOfListOfInteractive ite(List);
- while(ite.More()) {
- if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
- Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
- if(aSh->hasIO()) {
- Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
- if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
- if(!onlyInActiveView ||
- aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
- testResult = true;
- resultShape = aSh;
- return resultShape;
- }
- }
- }
- }
- ite.Next();
+ Handle(GEOM_AISShape) shape;
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
+ if ( obj ) {
+ QList<SUIT_ViewWindow*> views;
+ if ( onlyInActiveView )
+ views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
+ else
+ views = SUIT_Session::session()->activeApplication()->desktop()->windows();
+ foreach ( SUIT_ViewWindow* view, views ) {
+ if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
+ Handle(AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext();
+
+ AIS_ListOfInteractive displayed;
+ ic->DisplayedObjects( displayed );
+ ic->ObjectsInCollector( displayed );
+
+ AIS_ListIteratorOfListOfInteractive it( displayed );
+ while ( it.More() && shape.IsNull() ) {
+ if ( it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
+ Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
+ if ( !sh.IsNull() && sh->hasIO() ) {
+ Handle(SALOME_InteractiveObject) IO = Handle(SALOME_InteractiveObject)::DownCast( sh->getIO() );
+ if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() )
+ shape = sh;
+ }
+ }
+ it.Next();
+ }
+ }
+ if ( !shape.IsNull() ) break;
}
}
}
- return resultShape;
+ return shape;
}
// function : ConvertIORinGEOMActor()
// purpose :
//=======================================================================
-GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& testResult, bool onlyInActiveView)
+GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const QString& IOR, bool onlyInActiveView)
{
- testResult = false;
-
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return GEOM_Actor::New();
- _PTR(Study) aStudy = appStudy->studyDS();
-
- _PTR(SObject) anObj ( aStudy->FindObjectIOR( IOR ) );
- if ( !anObj )
- return GEOM_Actor::New();
-
- QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
-
- QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
- while ( it.hasNext() ) {
- SUIT_ViewWindow* aVW = it.next();
- if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
- SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
- if( !aVTKViewWindow )
- continue;
- vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
- vtkActorCollection* theActors = Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if( ac->IsA("GEOM_Actor")) {
- GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
- if(anActor->hasIO()) {
- Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
- if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
- if(!onlyInActiveView ||
- aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
- testResult = true;
- return anActor;
- }
- }
- }
- }
- ac = theActors->GetNextActor();
+ GEOM_Actor* actor = 0;
+
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ _PTR(SObject) obj( studyDS->FindObjectIOR( IOR.toLatin1().constData() ) );
+ if ( obj ) {
+ QList<SUIT_ViewWindow*> views;
+ if ( onlyInActiveView )
+ views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
+ else
+ views = SUIT_Session::session()->activeApplication()->desktop()->windows();
+ foreach ( SUIT_ViewWindow* view, views ) {
+ if ( view && view->getViewManager()->getType() == SVTK_Viewer::Type() ) {
+ SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( view );
+ if( !aVTKViewWindow )
+ continue;
+ vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
+ vtkActorCollection* theActors = Renderer->GetActors();
+ theActors->InitTraversal();
+ vtkActor* a = theActors->GetNextActor();
+ while( a && !actor ) {
+ if ( a->IsA( "GEOM_Actor" ) ) {
+ GEOM_Actor* ga = GEOM_Actor::SafeDownCast( a );
+ if ( ga && ga->hasIO() ) {
+ Handle(SALOME_InteractiveObject) IO = Handle(SALOME_InteractiveObject)::DownCast( ga->getIO() );
+ if ( !IO.IsNull() && IO->hasEntry() && obj->GetID() == IO->getEntry() )
+ actor = ga;
+ }
+ }
+ a = theActors->GetNextActor();
+ }
+ }
+ if ( actor ) break;
}
}
}
- testResult = false;
- return GEOM_Actor::New();
+ return actor;
}
//=======================================================================
// function : GetAIS()
// purpose :
//=======================================================================
-Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& theIO,
- const bool isOnlyInActiveView )
+Handle(AIS_InteractiveObject) GEOMBase::GetAIS( const Handle(SALOME_InteractiveObject)& IO,
+ bool onlyInActiveView, bool onlyGeom )
{
- if ( theIO.IsNull() || !theIO->hasEntry() )
- return Handle(AIS_InteractiveObject)();
-
- QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
-
- QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
- while ( it.hasNext() ) {
- SUIT_ViewWindow* aVW = it.next();
- if (!aVW || aVW->getViewManager()->getType() != OCCViewer_Viewer::Type())
- continue;
- Handle (AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
-
- AIS_ListOfInteractive aList;
- anIC->DisplayedObjects( aList );
- anIC->ObjectsInCollector( aList );
-
- AIS_ListIteratorOfListOfInteractive anIter( aList );
- for ( ; anIter.More(); anIter.Next() )
- {
- Handle(SALOME_InteractiveObject) anObj =
- Handle(SALOME_InteractiveObject)::DownCast( anIter.Value()->GetOwner() );
-
- if( !anObj.IsNull() && strcmp( anObj->getEntry(), theIO->getEntry() ) == 0 )
- {
- if( isOnlyInActiveView )
- {
- if ( aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow() )
- return anIter.Value();
- }
- else
- return anIter.Value();
+ Handle(AIS_InteractiveObject) aisObject;
+
+ if ( !IO.IsNull() && IO->hasEntry() ) {
+ QList<SUIT_ViewWindow*> views;
+ if ( onlyInActiveView )
+ views.append( SUIT_Session::session()->activeApplication()->desktop()->activeWindow() );
+ else
+ views = SUIT_Session::session()->activeApplication()->desktop()->windows();
+
+ foreach ( SUIT_ViewWindow* view, views ) {
+ if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
+ Handle(AIS_InteractiveContext) anIC = ((OCCViewer_Viewer*)view->getViewManager()->getViewModel())->getAISContext();
+
+ AIS_ListOfInteractive displayed;
+ anIC->DisplayedObjects( displayed );
+ anIC->ObjectsInCollector( displayed );
+
+ AIS_ListIteratorOfListOfInteractive it( displayed );
+ while ( it.More() && aisObject.IsNull() ) {
+ if ( onlyGeom && !it.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) )
+ continue;
+
+ Handle(SALOME_InteractiveObject) obj =
+ Handle(SALOME_InteractiveObject)::DownCast( it.Value()->GetOwner() );
+
+ if ( !obj.IsNull() && obj->isSame( IO ) )
+ aisObject = it.Value();
+ }
}
+ if ( !aisObject.IsNull() ) break;
}
}
- return Handle(AIS_InteractiveObject)();
+ return aisObject;
}
// function : ConvertIOinGEOMAISShape()
// purpose :
//=======================================================================
-Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult, bool onlyInActiveView)
+Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, bool onlyInActiveView )
{
- Handle(GEOM_AISShape) res;
-
- if ( !IO->hasEntry() )
- {
- testResult = false;
- return res;
- }
-
- QList<SUIT_ViewWindow*> aViewWindowsList = SUIT_Session::session()->activeApplication()->desktop()->windows();
-
- QListIterator<SUIT_ViewWindow*> it( aViewWindowsList );
- while ( it.hasNext() ) {
- SUIT_ViewWindow* aVW = it.next();
- if (aVW && aVW->getViewManager()->getType() == OCCViewer_Viewer::Type()) {
- Handle (AIS_InteractiveContext) ic = ((OCCViewer_Viewer*)aVW->getViewManager()->getViewModel())->getAISContext();
-
- AIS_ListOfInteractive List;
- ic->DisplayedObjects(List);
- AIS_ListOfInteractive List1;
- ic->ObjectsInCollector(List1);
- List.Append(List1);
-
- AIS_ListIteratorOfListOfInteractive ite(List);
- while(ite.More())
- {
- if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape)))
- {
- Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
- if( aSh->hasIO() )
- {
- if( strcmp( aSh->getIO()->getEntry(), IO->getEntry() ) == 0 )
- {
- if(onlyInActiveView)
- {
- if(aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow())
- {
- testResult = true;
- return aSh;
- }
- }
- else
- {
- testResult = true;
- return aSh;
- }
- }
- }
- }
- ite.Next();
- }
- }
- }
- testResult = false;
- return res;
+ return Handle(GEOM_AISShape)::DownCast( GetAIS( IO, onlyInActiveView, true ) );
}
//=======================================================================
-// function : ConvertIOinGEOMShape()
+// function : ConvertListOfIOInListOfIOR()
// purpose :
//=======================================================================
-GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO,
- Standard_Boolean& testResult)
+QStringList GEOMBase::ConvertListOfIOInListOfIOR( const SALOME_ListIO& IObjects )
{
- GEOM::GEOM_Object_var aShape;
- testResult = false;
-
- /* case SObject */
- if(IO->hasEntry()) {
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
- (SUIT_Session::session()->activeApplication()->activeStudy());
- if ( !appStudy ) return GEOM::GEOM_Object::_nil();
- _PTR(Study) aStudy = appStudy->studyDS();
-
- _PTR(SObject) obj ( aStudy->FindObjectID(IO->getEntry()) );
- _PTR(GenericAttribute) anAttr;
- if(obj) {
- if(obj->FindAttribute(anAttr, "AttributeIOR")) {
- _PTR(AttributeIOR) anIOR ( anAttr );
- aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
- if(!CORBA::is_nil(aShape))
- testResult = true;
- return aShape._retn();
- }
+ QStringList iors;
+ SALOME_ListIteratorOfListIO it( IObjects );
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ for ( ; it.More(); it.Next() ) {
+ GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() );
+ if ( !CORBA::is_nil( geomObj ) )
+ iors.append( GetIORFromObject( geomObj ) );
}
}
- return GEOM::GEOM_Object::_nil();
+ return iors;
}
//=======================================================================
-// function : ConvertListOfIOInListOfIOR()
+// function : ConvertIOinGEOMObject()
// purpose :
//=======================================================================
-void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::string_array& listIOR)
+GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& IO )
{
- int nbSel = aList.Extent();
- listIOR.length(nbSel);
- int j=0;
- SALOME_ListIteratorOfListIO It(aList);
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
- ( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- for (int i=0; It.More(); It.Next(), i++) {
- Handle(SALOME_InteractiveObject) IObject = It.Value();
- if (IObject->hasEntry()) {
- _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
- _PTR(GenericAttribute) anAttr;
- if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
- _PTR(AttributeIOR) anIOR (anAttr);
- //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
- // (aStudy.get())->ConvertIORToObject(anIOR->Value());
- CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
- if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
- listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
- j++;
- }
+ GEOM::GEOM_Object_var object;
+
+ if ( !IO.IsNull() && IO->hasEntry() ) {
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
+ _PTR(SObject) obj( studyDS->FindObjectID( IO->getEntry() ) );
+ if ( obj ) {
+ CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( obj );
+ if ( !CORBA::is_nil( corbaObj ) )
+ object = GEOM::GEOM_Object::_narrow( corbaObj );
}
}
}
- listIOR.length(j);
+ return object._retn();
}
//=======================================================================
-// function : ConvertIOinGEOMObject()
+// function : ConvertListOfIOInListOfGO()
// purpose :
//=======================================================================
-GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject (const Handle(SALOME_InteractiveObject)& theIO,
- Standard_Boolean& theResult)
+void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& IObjects,
+ GEOM::ListOfGO& geomObjects,
+ bool shapesOnly )
{
- theResult = Standard_False;
- GEOM::GEOM_Object_var aReturnObject;
-
- if (!theIO.IsNull())
- {
- const char* anEntry = theIO->getEntry();
+ geomObjects.length( 0 );
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
- (SUIT_Session::session()->activeApplication()->activeStudy());
- if (!appStudy) return GEOM::GEOM_Object::_nil();
- _PTR(Study) aStudy = appStudy->studyDS();
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
- _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry));
+ geomObjects.length( IObjects.Extent() );
+ SALOME_ListIteratorOfListIO it( IObjects );
- if (aSObj)
- {
- aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
- theResult = !CORBA::is_nil(aReturnObject);
+ int i = 0;
+ for ( ; it.More(); it.Next() ) {
+ GEOM::GEOM_Object_var geomObj = ConvertIOinGEOMObject( it.Value() );
+ if ( !CORBA::is_nil( geomObj ) && ( !shapesOnly || IsShape( geomObj ) ) )
+ geomObjects[ i++ ] = geomObj;
}
+ geomObjects.length( i );
}
- return aReturnObject._retn();
}
-//=======================================================================
-// function : ConvertListOfIOInListOfGO()
-// purpose :
-//=======================================================================
-void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
- GEOM::ListOfGO& theListGO,
- const bool theShapesOnly )
-{
- int nbSel = theList.Extent();
- theListGO.length( nbSel );
- SALOME_ListIteratorOfListIO anIter( theList );
-
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- int j = 0;
- for ( int i=0; anIter.More(); anIter.Next(), i++ )
- {
- Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
- _PTR(SObject) aSObj ( aStudy->FindObjectID( anIObj->getEntry() ) );
-
- if ( aSObj )
- {
- GEOM::GEOM_Object_var aGeomObj =
- GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
- if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
- theListGO[ j++ ] = aGeomObj;
- }
- }
-
- theListGO.length( j );
-}
-
//=================================================================================
// function : CreateArrowForLinearEdge()
// purpose : Create a cone topology to be used to display an arrow in the middle
// : of an edge showing its orientation. (For simulation and Viewer OCC only)
//=================================================================================
-bool GEOMBase::CreateArrowForLinearEdge(const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone)
+TopoDS_Shape GEOMBase::CreateArrowForLinearEdge( const TopoDS_Shape& shape )
{
- if(SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType()
- != OCCViewer_Viewer::Type() || tds.ShapeType() != TopAbs_EDGE)
- return false;
-
- OCCViewer_ViewPort3d* vp3d = ((OCCViewer_ViewWindow*)SUIT_Session::session()->activeApplication()->desktop()->activeWindow())->getViewPort();
- Handle( V3d_View) view3d = vp3d->getView();
- Standard_Real Width, Height;
- view3d->Size(Width, Height);
- const Standard_Real aHeight = (Width + Height) / 50.0;
-
- try {
- Standard_Real first, last;
- Handle(Geom_Curve) curv = BRep_Tool::Curve(TopoDS::Edge(tds), first, last);
- if(!curv->IsCN(1))
- return false;
-
- const Standard_Real param = (first+last) / 2.0;
- gp_Pnt middleParamPoint;
- gp_Vec V1;
- curv->D1( param, middleParamPoint, V1);
- if(V1.Magnitude() < Precision::Confusion())
- return false;
-
- /* Topology orientation not geom orientation */
- if(tds.Orientation() == TopAbs_REVERSED)
- V1 *= -1.0;
-
- gp_Ax2 anAxis( middleParamPoint, gp_Dir(V1));
- const Standard_Real radius1 = aHeight / 5.0;
- if(radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion()) {
- ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
- return true;
+ TopoDS_Shape ArrowCone;
+
+ SUIT_ViewWindow* view = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
+ if ( view && view->getViewManager()->getType() == OCCViewer_Viewer::Type() && shape.ShapeType() == TopAbs_EDGE ) {
+ Handle(V3d_View) view3d = ((OCCViewer_ViewWindow*)view)->getViewPort()->getView();
+ Standard_Real Width, Height;
+ view3d->Size( Width, Height );
+ const Standard_Real aHeight = (Width + Height) / 50.0;
+
+ try {
+ Standard_Real first, last;
+ Handle(Geom_Curve) curv = BRep_Tool::Curve( TopoDS::Edge( shape ), first, last );
+ if ( curv->IsCN(1) ) {
+ const Standard_Real param = ( first+last ) / 2.0;
+ gp_Pnt middleParamPoint;
+ gp_Vec V1;
+ curv->D1( param, middleParamPoint, V1 );
+ if ( V1.Magnitude() > Precision::Confusion() ) {
+ /* Topology orientation not geom orientation */
+ if ( shape.Orientation() == TopAbs_REVERSED )
+ V1 *= -1.0;
+
+ gp_Ax2 anAxis( middleParamPoint, gp_Dir( V1 ) );
+ const Standard_Real radius1 = aHeight / 5.0;
+ if ( radius1 > 10.0 * Precision::Confusion() && aHeight > 10.0 * Precision::Confusion() )
+ ArrowCone = BRepPrimAPI_MakeCone( anAxis, radius1, 0.0, aHeight ).Shape();
+ }
+ }
+ }
+ catch ( Standard_Failure ) {
+ // OCC failures are hard to catch in GUI.
+ // This is because of the position for #include <Standard_ErrorHandler.hxx> that is very critical to find
+ // in SALOME environment : compilation error !
}
}
- catch(Standard_Failure) {
- // OCC failures are hard to catch in GUI.
- // This because of the position for #include <Standard_ErrorHandler.hxx> that is very critic to find
- // in SALOME environment : compilation error !
- }
- return false;
+
+ return ArrowCone;
}
// function : VertexToPoint()
// purpose : If S can be converted in a gp_Pnt returns true and the result is P
//=================================================================================
-bool GEOMBase::VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P)
+bool GEOMBase::VertexToPoint( const TopoDS_Shape& shape, gp_Pnt& point )
{
- if(S.IsNull() || S.ShapeType() != TopAbs_VERTEX)
+ if ( shape.IsNull() || shape.ShapeType() != TopAbs_VERTEX )
return false;
- P = BRep_Tool::Pnt(TopoDS::Vertex(S));
+ point = BRep_Tool::Pnt( TopoDS::Vertex( shape ) );
return true;
}
// function : GetBipointDxDyDz()
// purpose :
//=================================================================================
-void GEOMBase::GetBipointDxDyDz(gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz)
+void GEOMBase::GetBipointDxDyDz( const gp_Pnt& point1, const gp_Pnt& point2, double& dx, double& dy, double& dz )
{
- dx = P2.X() - P1.X();
- dy = P2.Y() - P1.Y();
- dz = P2.Z() - P1.Z();
- return;
+ dx = point2.X() - point1.X();
+ dy = point2.Y() - point1.Y();
+ dz = point2.Z() - point1.Z();
}
// : distance is sufficient, returns true else returns false.
// : Resulting points are respectively P1 and P2
//=================================================================================
-bool GEOMBase::LinearEdgeExtremities(const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2)
+bool GEOMBase::LinearEdgeExtremities( const TopoDS_Shape& shape, gp_Pnt& point1, gp_Pnt& point2 )
{
- if(S.IsNull() || S.ShapeType() != TopAbs_EDGE)
+ if ( shape.IsNull() || shape.ShapeType() != TopAbs_EDGE )
return false;
- BRepAdaptor_Curve curv(TopoDS::Edge(S));
- if(curv.GetType() != GeomAbs_Line)
+
+ BRepAdaptor_Curve curv( TopoDS::Edge( shape ) );
+ if ( curv.GetType() != GeomAbs_Line )
return false;
+
+ gp_Pnt p1, p2;
- curv.D0(curv.FirstParameter(), P1);
- curv.D0(curv.LastParameter(), P2);
+ curv.D0( curv.FirstParameter(), p1 );
+ curv.D0( curv.LastParameter(), p2 );
- if(P1.Distance(P2) <= Precision::Confusion())
+ if ( p1.Distance( p2 ) <= Precision::Confusion() )
return false;
+ point1 = p1;
+ point2 = p2;
return true;
}
// : The selection is changed. Dialog box will receive the
// : corresponding signal to manage this event.
//=======================================================================
-bool GEOMBase::SelectionByNameInDialogs(QWidget* aWidget, const QString& objectUserName, const SALOME_ListIO& aList)
+bool GEOMBase::SelectionByNameInDialogs( QWidget* widget, const QString& objectUserName, const SALOME_ListIO& /*IObjects*/ )
{
/* Find SObject with name in component GEOM */
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return false;
- _PTR(Study) ST = appStudy->studyDS();
-
- std::vector<_PTR(SObject)> listSO;
- listSO = ST->FindObjectByName(objectUserName.toStdString(), "GEOM");
-
- if(listSO.size() < 1) {
- const QString caption = QObject::tr("GEOM_WRN_WARNING");
- const QString text = QObject::tr("GEOM_NAME_INCORRECT");
- const QString button0 = QObject::tr("GEOM_BUT_OK");
- SUIT_MessageBox::critical(aWidget, caption, text, button0);
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( !study ) return false;
+ _PTR(Study) studyDS = study->studyDS();
+
+ std::vector<_PTR(SObject)> listSO = studyDS->FindObjectByName( objectUserName.toStdString(), "GEOM" );
+
+ if ( listSO.size() < 1 ) {
+ SUIT_MessageBox::critical( widget,
+ QObject::tr( "GEOM_WRN_WARNING" ),
+ QObject::tr( "GEOM_NAME_INCORRECT" ),
+ QObject::tr( "GEOM_BUT_OK" ) );
return false;
}
+
/* More than one object with same name */
- if(listSO.size() > 1) {
- const QString caption = QObject::tr("GEOM_WRN_WARNING");
- const QString text = QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE");
- const QString button0 = QObject::tr("GEOM_BUT_OK") ;
- SUIT_MessageBox::critical(aWidget, caption, text, button0) ;
- listSO.clear();
+ if ( listSO.size() > 1 ) {
+ SUIT_MessageBox::critical( widget,
+ QObject::tr("GEOM_WRN_WARNING"),
+ QObject::tr("GEOM_IDENTICAL_NAMES_SELECT_BY_MOUSE"),
+ QObject::tr("GEOM_BUT_OK") );
return false;
}
- _PTR(SObject) theObj ( listSO[0] );
/* Create a SALOME_InteractiveObject with a SALOME::SObject */
- char* aCopyobjectUserName = CORBA::string_dup(objectUserName.toLatin1().constData());
- Handle(SALOME_InteractiveObject) SI = new SALOME_InteractiveObject(theObj->GetID().c_str(), "GEOM", aCopyobjectUserName);
- delete(aCopyobjectUserName);
+ Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject( listSO[0]->GetID().c_str(),
+ "GEOM",
+ objectUserName.toLatin1().constData() );
/* Add as a selected object */
/* Clear any previous selection : */
// function : DefineDlgPosition()
// purpose : Define x and y the default position for a dialog box
//=======================================================================
-bool GEOMBase::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
+void GEOMBase::DefineDlgPosition( QWidget* dlg, int& x, int& y )
{
/* Here the position is on the bottom right corner - 10 */
- SUIT_Desktop* PP = SUIT_Session::session()->activeApplication()->desktop();
- x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
- y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
- return true;
+ SUIT_Desktop* d = SUIT_Session::session()->activeApplication()->desktop();
+ x = abs( d->x() + d->size().width() - dlg->size().width() - 10 );
+ y = abs( d->y() + d->size().height() - dlg->size().height() - 10 );
}
// function : GetDefaultName()
// purpose : Generates default names
//=======================================================================
-QString GEOMBase::GetDefaultName(const QString& theOperation, const bool extractPrefix)
+QString GEOMBase::GetDefaultName( const QString& operation, bool extractPrefix )
{
QString aName = "";
// collect all object names of GEOM component
- SalomeApp_Study* appStudy =
- dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return aName;
- _PTR(Study) aStudy = appStudy->studyDS();
-
- std::set<std::string> aSet;
- _PTR(SComponent) aGeomCompo (aStudy->FindComponent("GEOM"));
- if (aGeomCompo) {
- _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeomCompo));
- _PTR(SObject) obj;
- for (it->InitEx(true); it->More(); it->Next()) {
- obj = it->Value();
- aSet.insert(obj->GetName());
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( study ) {
+ _PTR(Study) studyDS = study->studyDS();
+
+ std::set<std::string> names;
+ _PTR(SComponent) component( studyDS->FindComponent( "GEOM" ) );
+ if ( component ) {
+ _PTR(ChildIterator) it( studyDS->NewChildIterator( component ) );
+ for ( it->InitEx( true ); it->More(); it->Next() ) {
+ names.insert( it->Value()->GetName() );
+ }
}
- }
- // build a unique name
- int aNumber = 0;
- bool isUnique = false;
- QString prefix = theOperation;
-
- if ( extractPrefix ) {
- QStringList parts = prefix.split( "_", QString::KeepEmptyParts );
- if ( parts.count() > 1 ) {
- bool ok;
- aNumber = parts.last().toLong(&ok);
- if ( ok ) {
- parts.removeLast();
- prefix = parts.join( "_" );
- aNumber--;
+ // build a unique name
+ int aNumber = 0;
+ bool isUnique = false;
+ QString prefix = operation;
+
+ if ( extractPrefix ) {
+ QStringList parts = prefix.split( "_", QString::KeepEmptyParts );
+ if ( parts.count() > 1 ) {
+ bool ok;
+ aNumber = parts.last().toLong( &ok );
+ if ( ok ) {
+ parts.removeLast();
+ prefix = parts.join( "_" );
+ aNumber--;
+ }
}
}
+
+ while ( !isUnique ) {
+ aName = prefix + "_" + QString::number( ++aNumber );
+ isUnique = ( names.count( aName.toStdString()) == 0 );
+ }
}
-
- while (!isUnique) {
- aName = prefix + "_" + QString::number(++aNumber);
- isUnique = (aSet.count(aName.toStdString()) == 0);
- }
-
return aName;
}
// function : ShowErrorMessage()
// purpose : Shows message box with error code and comment
//=======================================================================
-void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment)
+void GEOMBase::ShowErrorMessage( const QString& errorCode, const QString& comment )
{
- QString anErrorCode(theErrorCode);
- QString aComment(theComment);
-
- QString aText = "";
- if (!anErrorCode.isEmpty())
- aText.append("\n" + QObject::tr(anErrorCode.toLatin1().constData()));
- if (!aComment.isEmpty())
- aText.append("\n" + QString(theComment));
-
- SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
- QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
+ QStringList text;
+ text << QObject::tr( "GEOM_PRP_ABORT" );
+ if ( !errorCode.isEmpty() )
+ text << QObject::tr( errorCode.toLatin1().constData() );
+ if ( !comment.isEmpty() )
+ text << QObject::tr( comment.toLatin1().constData() );
+
+ SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(),
+ QObject::tr( "GEOM_ERROR" ),
+ text.join( "\n" ),
+ QObject::tr( "GEOM_BUT_OK" ) );
}
// function : GetObjectFromIOR()
// purpose : returns a GEOM_Object by given IOR (string)
//=======================================================================
-GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const char* theIOR )
+GEOM::GEOM_Object_ptr GEOMBase::GetObjectFromIOR( const QString& IOR )
{
- GEOM::GEOM_Object_var anObject;
- if ( theIOR == NULL || strlen( theIOR ) == 0 )
- return anObject._retn(); // returning nil object
-
- anObject = GEOM::GEOM_Object::_narrow( SalomeApp_Application::orb()->string_to_object( theIOR ) );
- return anObject._retn();
+ GEOM::GEOM_Object_var geomObj;
+ if ( !IOR.isEmpty() ) {
+ CORBA::Object_var corbaObj = SalomeApp_Application::orb()->string_to_object( IOR.toLatin1().constData() );
+ if ( !CORBA::is_nil( corbaObj ) )
+ geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+ }
+ return geomObj._retn();
}
//=======================================================================
// function : GetIORFromObject()
// purpose : returns IOR of a given GEOM_Object
//=======================================================================
-QString GEOMBase::GetIORFromObject( const GEOM::GEOM_Object_ptr& theObject )
+QString GEOMBase::GetIORFromObject( GEOM::GEOM_Object_ptr object )
{
- if ( CORBA::is_nil( theObject ) )
- return NULL;
-
- return SalomeApp_Application::orb()->object_to_string( theObject );
+ QString IOR;
+ if ( !CORBA::is_nil( object ) ) {
+ CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( object );
+ IOR = anIOR.in();
+ }
+ return IOR;
}
//=======================================================================
// function : GetShape()
// purpose : returns a TopoDS_Shape stored in GEOM_Object
//=======================================================================
-bool GEOMBase::GetShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape, const TopAbs_ShapeEnum theType )
+bool GEOMBase::GetShape( GEOM::GEOM_Object_ptr object, TopoDS_Shape& shape, const TopAbs_ShapeEnum type )
{
- if ( !CORBA::is_nil( theObject ) )
- {
- TopoDS_Shape aTopoDSShape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObject );
- if ( !aTopoDSShape.IsNull() && ( theType == TopAbs_SHAPE || theType == aTopoDSShape.ShapeType() ) )
- {
- theShape = aTopoDSShape;
- return true;
- }
+ shape = TopoDS_Shape();
+ if ( !CORBA::is_nil( object ) ) {
+ TopAbs_ShapeEnum stype = (TopAbs_ShapeEnum)( object->GetShapeType() );
+ if ( type == TopAbs_SHAPE || type == stype )
+ shape = GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), object );
}
- return false;
+ return !shape.IsNull();
}
//=======================================================================
// function : GetName()
// purpose : Get name of object
//=======================================================================
-QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
+QString GEOMBase::GetName( GEOM::GEOM_Object_ptr object )
{
- SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
-
- if ( appStudy )
- {
- CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( theObj );
- if ( strcmp(anIOR.in(), "") != 0 )
- {
- _PTR(SObject) aSObj ( appStudy->studyDS()->FindObjectIOR( std::string( anIOR ) ) );
-
- _PTR(GenericAttribute) anAttr;
-
- if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
- {
- _PTR(AttributeName) aNameAttr ( anAttr );
- return QString( aNameAttr->Value().c_str() );
- }
+ QString name;
+ SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( object );
+ if ( study && strcmp( IOR.in(), "" ) != 0 ) {
+ _PTR(SObject) aSObj( study->studyDS()->FindObjectIOR( std::string( IOR.in() ) ) );
+ _PTR(GenericAttribute) anAttr;
+ if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) {
+ _PTR(AttributeName) aNameAttr( anAttr );
+ name = aNameAttr->Value().c_str();
}
}
- return QString("");
+ return name;
}
-bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr theObj )
+//=======================================================================
+// function : IsShape()
+// purpose : Return TRUE if object is valid and has shape
+//=======================================================================
+bool GEOMBase::IsShape( GEOM::GEOM_Object_ptr object )
{
- return !theObj->_is_nil() && theObj->IsShape();
+ return !object->_is_nil() && object->IsShape();
}