This commit is contained in:
jfa 2009-11-19 14:43:15 +00:00
parent a614e772f5
commit afcc3b209a

View File

@ -22,7 +22,7 @@
// GEOM GEOMGUI : GUI for Geometry component // GEOM GEOMGUI : GUI for Geometry component
// File : GEOMBase.cxx // File : GEOMBase.cxx
// Author : Damien COQUERET, Open CASCADE S.A.S. // Author : Damien COQUERET, Open CASCADE S.A.S.
//
#include "GEOMBase.h" #include "GEOMBase.h"
#include <GeometryGUI.h> #include <GeometryGUI.h>
@ -126,12 +126,12 @@ bool GEOMBase::GetTopoFromSelection(const SALOME_ListIO& aList, TopoDS_Shape& td
_PTR(GenericAttribute) anAttr; _PTR(GenericAttribute) anAttr;
if( obj ) { if( obj ) {
if(obj->FindAttribute(anAttr, "AttributeIOR")) { if(obj->FindAttribute(anAttr, "AttributeIOR")) {
_PTR(AttributeIOR) anIOR ( anAttr ); _PTR(AttributeIOR) anIOR ( anAttr );
tds = GetShapeFromIOR(anIOR->Value().c_str()); tds = GetShapeFromIOR(anIOR->Value().c_str());
if(tds.IsNull()) if(tds.IsNull())
return false; return false;
else else
return true; return true;
} }
} }
} }
@ -151,26 +151,26 @@ int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
{ {
int nbSel = aList.Extent(); int nbSel = aList.Extent();
if ( nbSel == 1 ) if ( nbSel == 1 )
{ {
Handle(SALOME_InteractiveObject) anIObj = aList.First(); Handle(SALOME_InteractiveObject) anIObj = aList.First();
if(anIObj->hasEntry()) { if(anIObj->hasEntry()) {
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() ); SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
if ( !appStudy ) return nbSel; if ( !appStudy ) return nbSel;
_PTR(Study) aStudy = appStudy->studyDS(); _PTR(Study) aStudy = appStudy->studyDS();
_PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) ); _PTR(SObject) obj ( aStudy->FindObjectID(anIObj->getEntry()) );
_PTR(GenericAttribute) anAttr; _PTR(GenericAttribute) anAttr;
if ( obj && obj->FindAttribute( anAttr, "AttributeName") ) if ( obj && obj->FindAttribute( anAttr, "AttributeName") )
{ {
_PTR(AttributeName) aNameAttr ( anAttr ); _PTR(AttributeName) aNameAttr ( anAttr );
theName = aNameAttr->Value().c_str(); theName = aNameAttr->Value().c_str();
} }
} }
} }
else else
theName = QObject::tr("%1_objects").arg(nbSel); theName = QObject::tr("%1_objects").arg(nbSel);
return nbSel; return nbSel;
} }
@ -179,10 +179,10 @@ int GEOMBase::GetNameOfSelectedIObjects( const SALOME_ListIO& aList,
GEOM::ListOfGO anObjs; GEOM::ListOfGO anObjs;
ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly ); ConvertListOfIOInListOfGO( aList, anObjs, theShapesOnly );
if ( anObjs.length() == 1 ) { if ( anObjs.length() == 1 ) {
theName = GetName( anObjs[ 0 ] ); theName = GetName( anObjs[ 0 ] );
} }
else else
theName = QString( "%1_objects" ).arg( anObjs.length() ); theName = QString( "%1_objects" ).arg( anObjs.length() );
return anObjs.length(); return anObjs.length();
} }
@ -203,88 +203,88 @@ bool GEOMBase::GetShapeTypeString(const TopoDS_Shape& aShape, Standard_CString&
{ {
case TopAbs_COMPOUND: case TopAbs_COMPOUND:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUND").toLatin1().constData());
return true; return true;
} }
case TopAbs_COMPSOLID: case TopAbs_COMPSOLID:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ; aTypeString = CORBA::string_dup(QObject::tr("GEOM_COMPOUNDSOLID").toLatin1().constData()) ;
return true ; return true ;
} }
case TopAbs_SOLID: case TopAbs_SOLID:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ; aTypeString = CORBA::string_dup(QObject::tr("GEOM_SOLID").toLatin1().constData()) ;
return true ; return true ;
} }
case TopAbs_SHELL: case TopAbs_SHELL:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ; aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHELL").toLatin1().constData()) ;
return true ; return true ;
} }
case TopAbs_FACE: case TopAbs_FACE:
{ {
BRepAdaptor_Surface surf(TopoDS::Face(aShape)); BRepAdaptor_Surface surf(TopoDS::Face(aShape));
if(surf.GetType() == GeomAbs_Plane) { if(surf.GetType() == GeomAbs_Plane) {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_PLANE").toLatin1().constData());
return true; return true;
} }
else if(surf.GetType() == GeomAbs_Cylinder) { else if(surf.GetType() == GeomAbs_Cylinder) {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCYLINDER").toLatin1().constData());
return true; return true;
} }
else if(surf.GetType() == GeomAbs_Sphere) { else if(surf.GetType() == GeomAbs_Sphere) {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFSPHERE").toLatin1().constData());
return true ; return true ;
} }
else if(surf.GetType() == GeomAbs_Torus) { else if(surf.GetType() == GeomAbs_Torus) {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFTORUS").toLatin1().constData());
return true ; return true ;
} }
else if(surf.GetType() == GeomAbs_Cone) { else if(surf.GetType() == GeomAbs_Cone) {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_SURFCONE").toLatin1().constData());
return true ; return true ;
} }
else { else {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_FACE").toLatin1().constData());
return true; return true;
} }
} }
case TopAbs_WIRE: case TopAbs_WIRE:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_WIRE").toLatin1().constData());
return true; return true;
} }
case TopAbs_EDGE: case TopAbs_EDGE:
{ {
BRepAdaptor_Curve curv(TopoDS::Edge(aShape)); BRepAdaptor_Curve curv(TopoDS::Edge(aShape));
if(curv.GetType() == GeomAbs_Line) { if(curv.GetType() == GeomAbs_Line) {
if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6)) if((Abs(curv.FirstParameter()) >= 1E6) || (Abs(curv.LastParameter()) >= 1E6))
aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_LINE").toLatin1().constData());
else else
aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
return true; return true;
} }
else if(curv.GetType() == GeomAbs_Circle) { else if(curv.GetType() == GeomAbs_Circle) {
if(curv.IsClosed()) if(curv.IsClosed())
aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_CIRCLE").toLatin1().constData());
else else
aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_ARC").toLatin1().constData());
return true; return true;
} }
else { else {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_EDGE").toLatin1().constData());
return true; return true;
} }
} }
case TopAbs_VERTEX: case TopAbs_VERTEX:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_VERTEX").toLatin1().constData());
return true; return true;
} }
case TopAbs_SHAPE: case TopAbs_SHAPE:
{ {
aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData()); aTypeString = CORBA::string_dup(QObject::tr("GEOM_SHAPE").toLatin1().constData());
return true; return true;
} }
} }
return false; return false;
@ -324,21 +324,21 @@ Handle(GEOM_AISShape) GEOMBase::ConvertIORinGEOMAISShape(const char * IOR, Stand
AIS_ListIteratorOfListOfInteractive ite(List); AIS_ListIteratorOfListOfInteractive ite(List);
while(ite.More()) { while(ite.More()) {
if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
if(aSh->hasIO()) { if(aSh->hasIO()) {
Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO()); Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(aSh->getIO());
if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) { if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
if(!onlyInActiveView || if(!onlyInActiveView ||
aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) { aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
testResult = true; testResult = true;
resultShape = aSh; resultShape = aSh;
return resultShape; return resultShape;
} }
} }
} }
} }
ite.Next(); ite.Next();
} }
} }
} }
@ -370,26 +370,26 @@ GEOM_Actor* GEOMBase::ConvertIORinGEOMActor(const char* IOR, Standard_Boolean& t
if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) { if (aVW && aVW->getViewManager()->getType() == SVTK_Viewer::Type()) {
SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW ); SVTK_ViewWindow* aVTKViewWindow = dynamic_cast<SVTK_ViewWindow*>( aVW );
if( !aVTKViewWindow ) if( !aVTKViewWindow )
continue; continue;
vtkRenderer* Renderer = aVTKViewWindow->getRenderer(); vtkRenderer* Renderer = aVTKViewWindow->getRenderer();
vtkActorCollection* theActors = Renderer->GetActors(); vtkActorCollection* theActors = Renderer->GetActors();
theActors->InitTraversal(); theActors->InitTraversal();
vtkActor *ac = theActors->GetNextActor(); vtkActor *ac = theActors->GetNextActor();
while(!(ac==NULL)) { while(!(ac==NULL)) {
if( ac->IsA("GEOM_Actor")) { if( ac->IsA("GEOM_Actor")) {
GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac); GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(ac);
if(anActor->hasIO()) { if(anActor->hasIO()) {
Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO()); Handle(SALOME_InteractiveObject) GIO = Handle(SALOME_InteractiveObject)::DownCast(anActor->getIO());
if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) { if(GIO->hasEntry() && strcmp(GIO->getEntry(), anObj->GetID().c_str()) == 0) {
if(!onlyInActiveView || if(!onlyInActiveView ||
aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) { aVW == SUIT_Session::session()->activeApplication()->desktop()->activeWindow()) {
testResult = true; testResult = true;
return anActor; return anActor;
} }
} }
} }
} }
ac = theActors->GetNextActor(); ac = theActors->GetNextActor();
} }
} }
} }
@ -510,14 +510,16 @@ Handle(GEOM_AISShape) GEOMBase::ConvertIOinGEOMAISShape(const Handle(SALOME_Inte
// function : ConvertIOinGEOMShape() // function : ConvertIOinGEOMShape()
// purpose : // purpose :
//======================================================================= //=======================================================================
GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject)& IO,
Standard_Boolean& testResult)
{ {
GEOM::GEOM_Object_var aShape; GEOM::GEOM_Object_var aShape;
testResult = false; testResult = false;
/* case SObject */ /* case SObject */
if(IO->hasEntry()) { if(IO->hasEntry()) {
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() ); SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
(SUIT_Session::session()->activeApplication()->activeStudy());
if ( !appStudy ) return GEOM::GEOM_Object::_nil(); if ( !appStudy ) return GEOM::GEOM_Object::_nil();
_PTR(Study) aStudy = appStudy->studyDS(); _PTR(Study) aStudy = appStudy->studyDS();
@ -525,11 +527,11 @@ GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMShape(const Handle(SALOME_Interac
_PTR(GenericAttribute) anAttr; _PTR(GenericAttribute) anAttr;
if(obj) { if(obj) {
if(obj->FindAttribute(anAttr, "AttributeIOR")) { if(obj->FindAttribute(anAttr, "AttributeIOR")) {
_PTR(AttributeIOR) anIOR ( anAttr ); _PTR(AttributeIOR) anIOR ( anAttr );
aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str()); aShape = GeometryGUI::GetGeomGen()->GetIORFromString(anIOR->Value().c_str());
if(!CORBA::is_nil(aShape)) if(!CORBA::is_nil(aShape))
testResult = true; testResult = true;
return aShape._retn(); return aShape._retn();
} }
} }
} }
@ -558,14 +560,14 @@ void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::stri
_PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) ); _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
_PTR(GenericAttribute) anAttr; _PTR(GenericAttribute) anAttr;
if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) { if (obj && obj->FindAttribute(anAttr, "AttributeIOR")) {
_PTR(AttributeIOR) anIOR (anAttr); _PTR(AttributeIOR) anIOR (anAttr);
//CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*> //CORBA::Object_var theObj = dynamic_cast<SALOMEDS_Study*>
// (aStudy.get())->ConvertIORToObject(anIOR->Value()); // (aStudy.get())->ConvertIORToObject(anIOR->Value());
CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj); CORBA::Object_var theObj = GeometryGUI::ClientSObjectToObject(obj);
if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) { if (!CORBA::is_nil(theObj) && theObj->_is_a("IDL:GEOM/GEOM_Object:1.0")) {
listIOR[j] = CORBA::string_dup(anIOR->Value().c_str()); listIOR[j] = CORBA::string_dup(anIOR->Value().c_str());
j++; j++;
} }
} }
} }
} }
@ -577,26 +579,27 @@ void GEOMBase::ConvertListOfIOInListOfIOR(const SALOME_ListIO& aList, GEOM::stri
// function : ConvertIOinGEOMObject() // function : ConvertIOinGEOMObject()
// purpose : // purpose :
//======================================================================= //=======================================================================
GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject( const Handle(SALOME_InteractiveObject)& theIO, GEOM::GEOM_Object_ptr GEOMBase::ConvertIOinGEOMObject (const Handle(SALOME_InteractiveObject)& theIO,
Standard_Boolean& theResult ) Standard_Boolean& theResult)
{ {
theResult = Standard_False; theResult = Standard_False;
GEOM::GEOM_Object_var aReturnObject; GEOM::GEOM_Object_var aReturnObject;
if ( !theIO.IsNull() )
if (!theIO.IsNull())
{ {
const char* anEntry = theIO->getEntry(); const char* anEntry = theIO->getEntry();
SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*> SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
( SUIT_Session::session()->activeApplication()->activeStudy() ); (SUIT_Session::session()->activeApplication()->activeStudy());
if ( !appStudy ) return GEOM::GEOM_Object::_nil(); if (!appStudy) return GEOM::GEOM_Object::_nil();
_PTR(Study) aStudy = appStudy->studyDS(); _PTR(Study) aStudy = appStudy->studyDS();
_PTR(SObject) aSObj ( aStudy->FindObjectID( anEntry ) ); _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry));
if (aSObj) if (aSObj)
{ {
aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); aReturnObject = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
theResult = !CORBA::is_nil( aReturnObject ); theResult = !CORBA::is_nil(aReturnObject);
} }
} }
return aReturnObject._retn(); return aReturnObject._retn();
@ -628,7 +631,7 @@ void GEOMBase::ConvertListOfIOInListOfGO( const SALOME_ListIO& theList,
if ( aSObj ) if ( aSObj )
{ {
GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object_var aGeomObj =
GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj)); GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) ) if ( !CORBA::is_nil( aGeomObj ) && ( !theShapesOnly || IsShape( aGeomObj ) ) )
theListGO[ j++ ] = aGeomObj; theListGO[ j++ ] = aGeomObj;
} }
@ -852,7 +855,7 @@ void GEOMBase::ShowErrorMessage(const char* theErrorCode, const char* theComment
aText.append("\n" + QString(theComment)); aText.append("\n" + QString(theComment));
SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ), SUIT_MessageBox::critical( SUIT_Session::session()->activeApplication()->desktop(), QObject::tr( "GEOM_ERROR" ),
QObject::tr("GEOM_PRP_ABORT") + aText, "OK" ); QObject::tr("GEOM_PRP_ABORT") + aText, "OK" );
} }
@ -920,7 +923,7 @@ QString GEOMBase::GetName( GEOM::GEOM_Object_ptr theObj )
if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") ) if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
{ {
_PTR(AttributeName) aNameAttr ( anAttr ); _PTR(AttributeName) aNameAttr ( anAttr );
return QString( aNameAttr->Value().c_str() ); return QString( aNameAttr->Value().c_str() );
} }
} }
} }