2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
|
2008-03-07 12:45:34 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
2008-03-07 12:45:34 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
2005-12-05 21:23:52 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
2005-12-05 21:23:52 +05:00
|
|
|
//
|
2009-02-13 17:16:39 +05:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2005-12-05 21:23:52 +05:00
|
|
|
//
|
2005-08-11 10:14:22 +06:00
|
|
|
#ifdef WNT
|
|
|
|
#pragma warning( disable:4786 )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Standard_Stream.hxx>
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
#include "GEOM_Gen_i.hh"
|
|
|
|
#include "GEOM_Object_i.hh"
|
2005-06-02 13:17:09 +06:00
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
#include <strstream>
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
#include "Utils_CorbaException.hxx"
|
|
|
|
#include "OpUtil.hxx"
|
|
|
|
#include "Utils_ExceptHandlers.hxx"
|
|
|
|
#include "utilities.h"
|
|
|
|
|
|
|
|
#include "GEOM_Object_i.hh"
|
|
|
|
#include "GEOM_Object.hxx"
|
|
|
|
#include "GEOM_Function.hxx"
|
|
|
|
#include "GEOMImpl_Types.hxx"
|
|
|
|
#include "GEOMImpl_CopyDriver.hxx"
|
|
|
|
|
|
|
|
// Cascade headers
|
|
|
|
#include <BRep_Builder.hxx>
|
|
|
|
#include <BRepTools.hxx>
|
|
|
|
#include <TDF_Label.hxx>
|
|
|
|
#include <TDF_Tool.hxx>
|
|
|
|
#include <TCollection_AsciiString.hxx>
|
|
|
|
#include <TColStd_HArray1OfInteger.hxx>
|
|
|
|
#include <TopAbs_ShapeEnum.hxx>
|
2006-03-13 20:11:51 +05:00
|
|
|
#include <OSD.hxx>
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2005-06-02 13:17:09 +06:00
|
|
|
#include "SALOMEDS_Tool.hxx"
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
// function : GEOM_Gen_i()
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose : constructor to be called for servant creation.
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
|
|
|
|
PortableServer::POA_ptr poa,
|
2005-08-18 12:15:31 +06:00
|
|
|
PortableServer::ObjectId * contId,
|
|
|
|
const char *instanceName,
|
2004-12-01 15:39:14 +05:00
|
|
|
const char *interfaceName) :
|
|
|
|
Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
|
|
|
|
{
|
2005-08-18 12:15:31 +06:00
|
|
|
_thisObj = this;
|
2004-12-01 15:39:14 +05:00
|
|
|
_id = _poa->activate_object(_thisObj);
|
|
|
|
name_service = new SALOME_NamingService(_orb);
|
|
|
|
|
|
|
|
_impl = new ::GEOMImpl_Gen;
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
//PAL10867: disable signals catching with "noexcepthandler" option
|
|
|
|
char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
|
|
|
|
if (!envNoCatchSignals || !atoi(envNoCatchSignals))
|
|
|
|
{
|
|
|
|
//work around PAL12004, PAL12628
|
|
|
|
//OSD::SetSignal( true );
|
|
|
|
bool raiseFPE;
|
|
|
|
#ifdef _DEBUG_
|
|
|
|
raiseFPE = true;
|
|
|
|
char* envDisableFPE = getenv("DISABLE_FPE");
|
|
|
|
if (envDisableFPE && atoi(envDisableFPE))
|
|
|
|
raiseFPE = false;
|
|
|
|
#else
|
|
|
|
raiseFPE = false;
|
|
|
|
#endif
|
|
|
|
OSD::SetSignal( raiseFPE );
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : ~GEOM_Gen_i()
|
|
|
|
// purpose : destructor
|
|
|
|
//============================================================================
|
|
|
|
GEOM_Gen_i::~GEOM_Gen_i() {
|
|
|
|
delete name_service;
|
|
|
|
delete _impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : IORToLocalPersistentID()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
|
|
|
|
const char* IORString,
|
|
|
|
CORBA::Boolean isMultiFile,
|
|
|
|
CORBA::Boolean isASCII)
|
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
|
|
|
|
if (!CORBA::is_nil(anObject)) {
|
2008-03-07 12:45:34 +05:00
|
|
|
return CORBA::string_dup(anObject->GetEntry());
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : LocalPersistentIDToIOR()
|
|
|
|
// purpose : Create/Load CORBA object from a persistent ref (an entry)
|
|
|
|
// : Used when a study is loaded
|
|
|
|
// : The IOR (IORName) of object created is returned
|
|
|
|
//============================================================================
|
|
|
|
char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
|
|
|
|
const char* aLocalPersistentID,
|
|
|
|
CORBA::Boolean isMultiFile,
|
2005-08-18 12:15:31 +06:00
|
|
|
CORBA::Boolean isASCII)
|
|
|
|
{
|
2004-12-01 15:39:14 +05:00
|
|
|
SALOMEDS::Study_var aStudy = theSObject->GetStudy();
|
|
|
|
|
|
|
|
Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
|
2005-08-18 12:15:31 +06:00
|
|
|
TCollection_AsciiString anEntry;
|
|
|
|
TDF_Tool::Entry(anObject->GetEntry(), anEntry);
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
|
|
|
|
|
|
|
|
CORBA::String_var aPersRefString = _orb->object_to_string(obj);
|
2008-03-07 12:45:34 +05:00
|
|
|
return CORBA::string_dup(aPersRefString);
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : CanPublishInStudy
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
|
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
|
|
|
|
return !(anObject->_is_nil());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : PublishInStudy
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
|
|
|
|
SALOMEDS::SObject_ptr theSObject,
|
|
|
|
CORBA::Object_ptr theObject,
|
|
|
|
const char* theName) throw (SALOME::SALOME_Exception)
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
SALOMEDS::SObject_var aResultSO;
|
|
|
|
if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
|
|
|
|
GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
|
|
|
|
if(aShape->_is_nil()) return aResultSO;
|
|
|
|
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
2005-08-18 12:15:31 +06:00
|
|
|
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
|
2004-12-01 15:39:14 +05:00
|
|
|
if (aFather->_is_nil()) {
|
|
|
|
aFather = aStudyBuilder->NewComponent("GEOM");
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
|
|
|
|
SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
|
|
|
|
aName->SetValue("Geometry");
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
|
|
|
|
SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
|
|
|
|
aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
|
|
|
|
}
|
|
|
|
if (aFather->_is_nil()) return aResultSO;
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
if (CORBA::is_nil(theSObject)) {
|
|
|
|
aResultSO = aStudyBuilder->NewObject(aFather);
|
|
|
|
} else {
|
2005-08-18 12:15:31 +06:00
|
|
|
if (!theSObject->ReferencedObject(aResultSO))
|
2004-12-01 15:39:14 +05:00
|
|
|
aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
|
|
|
|
//THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
|
|
|
|
}
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
|
|
|
|
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
2008-03-07 12:45:34 +05:00
|
|
|
//char *aGeomObjIOR = _orb->object_to_string(theObject);
|
|
|
|
CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
|
|
|
|
//anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
|
|
|
|
anIOR->SetValue(aGeomObjIOR);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
|
|
|
|
SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
|
2005-08-18 12:15:31 +06:00
|
|
|
TCollection_AsciiString aShapeName("Shape_");
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
if ( aShape->GetType() == GEOM_GROUP ) {
|
|
|
|
GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
|
|
|
|
switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
|
|
|
|
case TopAbs_VERTEX:
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
|
|
|
|
aShapeName = "Group_Of_Vertices_";
|
|
|
|
break;
|
|
|
|
case TopAbs_EDGE:
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
|
|
|
|
aShapeName = "Group_Of_Edges_";
|
|
|
|
break;
|
|
|
|
case TopAbs_FACE:
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
|
|
|
|
aShapeName = "Group_Of_Faces_";
|
|
|
|
break;
|
|
|
|
case TopAbs_SOLID:
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
|
|
|
|
aShapeName = "Group_Of_Solids_";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if ( aShape->GetType() == GEOM_MARKER ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
|
|
|
|
aShapeName = "LocalCS_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
|
|
|
|
aShapeName = "Compound_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
|
|
|
|
aShapeName = "Compsolid_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::SOLID ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
|
|
|
|
aShapeName = "Solid_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::SHELL ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
|
|
|
|
aShapeName = "Shell_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::FACE ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
|
|
|
|
aShapeName = "Face_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::WIRE ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
|
|
|
|
aShapeName = "Wire_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::EDGE ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
|
|
|
|
aShapeName = "Edge_";
|
|
|
|
} else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
|
|
|
|
aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
|
|
|
|
aShapeName = "Vertex_";
|
2005-08-18 12:15:31 +06:00
|
|
|
}
|
2004-12-17 16:18:33 +05:00
|
|
|
//if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
|
2008-03-07 12:45:34 +05:00
|
|
|
//else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
|
2004-12-17 16:18:33 +05:00
|
|
|
|
|
|
|
// asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
|
|
|
|
// it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
|
|
|
|
// of objects in the study, but compute a number of objects with the same prefix
|
|
|
|
// and build a new name as Prefix_N+1
|
|
|
|
if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
|
|
|
|
int i = 0; // (WITH EMPTY NEW NAME)
|
|
|
|
SALOMEDS::SObject_var obj;
|
|
|
|
TCollection_AsciiString aNewShapeName;
|
|
|
|
do {
|
|
|
|
aNewShapeName = aShapeName + TCollection_AsciiString(++i);
|
|
|
|
obj = theStudy->FindObject( aNewShapeName.ToCString() );
|
2005-08-18 12:15:31 +06:00
|
|
|
}
|
2004-12-17 16:18:33 +05:00
|
|
|
while ( !obj->_is_nil() );
|
|
|
|
aShapeName = aNewShapeName;
|
|
|
|
}
|
|
|
|
else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
|
2008-03-07 12:45:34 +05:00
|
|
|
aShapeName = TCollection_AsciiString((char*)theName);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
//Set the study entry as a name of the published GEOM_Object
|
|
|
|
aShape->SetStudyEntry(aResultSO->GetID());
|
|
|
|
|
|
|
|
//Set a name of the added shape
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
|
|
|
|
SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
|
|
|
|
aNameAttrib->SetValue(aShapeName.ToCString());
|
2009-02-13 17:16:39 +05:00
|
|
|
|
|
|
|
//Set NoteBook variables used in the object creation
|
|
|
|
TCollection_AsciiString aVars;
|
|
|
|
SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
|
|
|
|
for(int i = 0, n = aSections->length(); i < n; i++) {
|
|
|
|
SALOMEDS::ListOfStrings aListOfVars = aSections[i];
|
|
|
|
for(int j = 0, m = aListOfVars.length(); j < m; j++) {
|
|
|
|
if(theStudy->IsVariable(aListOfVars[j].in()))
|
|
|
|
aVars += TCollection_AsciiString(aListOfVars[j].in());
|
|
|
|
if(j != m-1)
|
|
|
|
aVars += ":";
|
|
|
|
}
|
|
|
|
if(i != n-1)
|
|
|
|
aVars += "|";
|
|
|
|
}
|
|
|
|
anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
|
|
|
|
SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
|
|
|
|
aStringAttrib->SetValue(aVars.ToCString());
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
//Set a name of the GEOM object
|
|
|
|
aShape->SetName(theName);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
return aResultSO._retn();
|
|
|
|
}
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
// function : Save()
|
|
|
|
// purpose : save OCAF/Geom document
|
|
|
|
//============================================================================
|
|
|
|
SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
|
|
|
|
const char* theURL,
|
|
|
|
bool isMultiFile) {
|
|
|
|
SALOMEDS::TMPFile_var aStreamFile;
|
|
|
|
// Get a temporary directory to store a file
|
|
|
|
std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
// OCCT BUG: cannot save a document (in current folder)
|
|
|
|
// if directory name is empty
|
|
|
|
if (aTmpDir.size() == 0) {
|
|
|
|
#ifdef WNT
|
|
|
|
aTmpDir = ".\\";
|
|
|
|
#else
|
|
|
|
aTmpDir = "./";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
// Create a list to store names of created files
|
|
|
|
SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
|
|
|
|
aSeq->length(1);
|
|
|
|
// Prepare a file name to open
|
|
|
|
TCollection_AsciiString aNameWithExt("");
|
|
|
|
if (isMultiFile)
|
|
|
|
aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
|
|
|
|
aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
|
|
|
|
aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
|
|
|
|
// Build a full file name of temporary file
|
|
|
|
TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
|
|
|
|
// Save GEOM component in this file
|
2009-02-13 17:16:39 +05:00
|
|
|
_impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
|
2004-12-01 15:39:14 +05:00
|
|
|
// Conver a file to the byte stream
|
|
|
|
aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
|
|
|
|
// Remove the created file and tmp directory
|
|
|
|
if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
|
|
|
|
|
|
|
|
// Return the created byte stream
|
|
|
|
return aStreamFile._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : SaveASCII()
|
|
|
|
// purpose :
|
2005-08-18 12:15:31 +06:00
|
|
|
//============================================================================
|
2004-12-01 15:39:14 +05:00
|
|
|
SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
|
|
|
|
const char* theURL,
|
|
|
|
bool isMultiFile) {
|
|
|
|
SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
|
|
|
|
return aStreamFile._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : Load()
|
|
|
|
// purpose :
|
2005-08-18 12:15:31 +06:00
|
|
|
//============================================================================
|
2004-12-01 15:39:14 +05:00
|
|
|
CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
|
|
|
|
const SALOMEDS::TMPFile& theStream,
|
|
|
|
const char* theURL,
|
|
|
|
bool isMultiFile) {
|
|
|
|
|
|
|
|
if (theStream.length() <= 9) {
|
|
|
|
MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a temporary directory for a file
|
|
|
|
std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
|
2008-03-07 12:45:34 +05:00
|
|
|
|
|
|
|
// OCCT BUG: cannot load a document (from current folder)
|
|
|
|
// if directory name is empty
|
|
|
|
if (aTmpDir.size() == 0) {
|
|
|
|
#ifdef WNT
|
|
|
|
aTmpDir = ".\\";
|
|
|
|
#else
|
|
|
|
aTmpDir = "./";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
// Conver the byte stream theStream to a file and place it in tmp directory
|
2008-03-07 12:45:34 +05:00
|
|
|
SALOMEDS::ListOfFileNames_var aSeq =
|
|
|
|
SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
// Prepare a file name to open
|
|
|
|
TCollection_AsciiString aNameWithExt("");
|
|
|
|
if (isMultiFile)
|
|
|
|
aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
|
|
|
|
aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
|
|
|
|
TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
|
|
|
|
|
|
|
|
// Open document
|
2009-02-13 17:16:39 +05:00
|
|
|
if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
// Remove the created file and tmp directory
|
|
|
|
if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
|
|
|
|
|
|
|
|
SALOMEDS::Study_var Study = theComponent->GetStudy();
|
2008-03-07 12:45:34 +05:00
|
|
|
TCollection_AsciiString name (Study->Name());
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : LoadASCII()
|
|
|
|
// purpose :
|
2005-08-18 12:15:31 +06:00
|
|
|
//============================================================================
|
2004-12-01 15:39:14 +05:00
|
|
|
CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
|
|
|
|
const SALOMEDS::TMPFile& theStream,
|
|
|
|
const char* theURL,
|
|
|
|
bool isMultiFile) {
|
|
|
|
return Load(theComponent, theStream, theURL, isMultiFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : Close()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
|
|
|
|
{
|
|
|
|
_impl->Close(theComponent->GetStudy()->StudyId());
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : CanCopy()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
|
|
|
|
// Try to retrieve known by Geometry component GEOM_Object by given IOR
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
|
|
|
if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
|
|
|
|
|
|
|
|
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
|
|
|
|
|
|
|
GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
|
|
|
|
// If the object is null one it can't be copied: return false
|
|
|
|
if (anObject->_is_nil()) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : CopyFrom()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
|
|
|
|
// Declare a sequence of the byte to store the copied object
|
|
|
|
SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
|
|
|
|
|
|
|
|
// Try to get GEOM_Object object by given SObject
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
|
|
|
if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
|
|
|
|
GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
|
|
|
|
if (anObject->_is_nil()) return aStreamFile._retn();
|
|
|
|
|
|
|
|
aStreamFile = anObject->GetShapeStream();
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
// Assign an ID the type of GEOM_Object
|
|
|
|
theObjectID = anObject->GetType();
|
|
|
|
|
|
|
|
// Return created TMPFile
|
|
|
|
return aStreamFile._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : CanPaste()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
|
|
|
|
// The Geometry component can paste only objects copied by Geometry component
|
|
|
|
// and with the object type = 1
|
|
|
|
if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : PasteInto()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
|
|
|
|
CORBA::Long theObjectID,
|
|
|
|
SALOMEDS::SObject_ptr theObject) {
|
|
|
|
// Find the current Study and StudyBuilder
|
|
|
|
SALOMEDS::Study_var aStudy = theObject->GetStudy();
|
|
|
|
SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
|
|
|
|
|
|
|
|
// Retrieve a TopoDS_Shape from byte stream
|
|
|
|
TopoDS_Shape aTopology;
|
|
|
|
istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
|
|
|
|
BRep_Builder aBuilder;
|
|
|
|
try {
|
|
|
|
BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
|
|
|
|
} catch (Standard_Failure) {
|
|
|
|
return false;
|
|
|
|
}
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
// SObject of the created shape is theObject or new Child of Component if theObject == geom component
|
|
|
|
SALOMEDS::SObject_var aNewSO;
|
|
|
|
if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
|
|
|
|
aNewSO = aStudyBuilder->NewObject(theObject);
|
|
|
|
} else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
|
|
|
|
//Create a new GEOM_Object
|
|
|
|
Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
|
|
|
|
Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
|
2004-12-01 15:39:14 +05:00
|
|
|
aFunction->SetValue(aTopology);
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
TCollection_AsciiString anEntry;
|
|
|
|
TDF_Tool::Entry(anObj->GetEntry(), anEntry);
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
|
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
//Set the study entry of the published GEOM_Object
|
|
|
|
obj->SetStudyEntry(aNewSO->GetID());
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
// Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
|
|
|
|
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
2008-03-07 12:45:34 +05:00
|
|
|
CORBA::String_var objStr = _orb->object_to_string(obj);
|
|
|
|
anIOR->SetValue(objStr.in());
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
// Return the created in the Study SObject
|
|
|
|
return aNewSO._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : ComponentDataType()
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
char* GEOM_Gen_i::ComponentDataType()
|
|
|
|
{
|
2008-03-07 12:45:34 +05:00
|
|
|
return CORBA::string_dup("GEOM");
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : AddInStudy
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
2009-02-13 17:16:39 +05:00
|
|
|
SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
|
|
|
|
GEOM::GEOM_Object_ptr theObject,
|
|
|
|
const char* theName,
|
|
|
|
GEOM::GEOM_Object_ptr theFather)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
SALOMEDS::SObject_var aResultSO;
|
|
|
|
if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
|
2005-08-18 12:15:31 +06:00
|
|
|
|
|
|
|
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
|
2008-03-07 12:45:34 +05:00
|
|
|
CORBA::String_var IOR;
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
if(!theFather->_is_nil()) {
|
2005-08-18 12:15:31 +06:00
|
|
|
IOR = _orb->object_to_string(theFather);
|
2008-03-07 12:45:34 +05:00
|
|
|
SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
|
2004-12-01 15:39:14 +05:00
|
|
|
if(aFatherSO->_is_nil()) return aResultSO._retn();
|
|
|
|
aResultSO = aStudyBuilder->NewObject(aFatherSO);
|
|
|
|
//aStudyBuilder->Addreference(aResultSO, aResultSO);
|
2005-08-18 12:15:31 +06:00
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
|
|
|
|
if(aResultSO->_is_nil()) return aResultSO._retn();
|
|
|
|
|
|
|
|
GEOM::ListOfGO_var aList = theObject->GetDependency();
|
2005-08-18 12:15:31 +06:00
|
|
|
Standard_Integer aLength = aList->length();
|
2004-12-01 15:39:14 +05:00
|
|
|
if(aLength < 1) return aResultSO._retn();
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
//Publish the arguments
|
2004-12-01 15:39:14 +05:00
|
|
|
for(Standard_Integer i = 0; i< aLength; i++) {
|
|
|
|
GEOM::GEOM_Object_var anObject = aList[i];
|
|
|
|
if(anObject->_is_nil()) continue;
|
|
|
|
IOR = _orb->object_to_string(anObject);
|
2008-03-07 12:45:34 +05:00
|
|
|
SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
|
2004-12-01 15:39:14 +05:00
|
|
|
if(aSO->_is_nil()) continue;
|
|
|
|
SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
|
|
|
|
aStudyBuilder->Addreference(aSubSO, aSO);
|
|
|
|
}
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
return aResultSO._retn();
|
|
|
|
}
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
//============================================================================
|
|
|
|
// function : RestoreSubShapesO
|
|
|
|
// purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
|
|
|
|
// To be used from python scripts out of geompy.addToStudy (non-default usage)
|
|
|
|
//============================================================================
|
|
|
|
CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
|
|
|
|
GEOM::GEOM_Object_ptr theObject,
|
|
|
|
const GEOM::ListOfGO& theArgs,
|
|
|
|
GEOM::find_shape_method theFindMethod,
|
|
|
|
CORBA::Boolean theInheritFirstArg)
|
|
|
|
{
|
|
|
|
if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// find SObject in the study
|
|
|
|
CORBA::String_var anIORo = _orb->object_to_string(theObject);
|
|
|
|
SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
|
|
|
|
if (CORBA::is_nil(aSO))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : RestoreSubShapesSO
|
|
|
|
// purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
|
|
|
|
// To be used from GUI and from geompy.addToStudy
|
|
|
|
//============================================================================
|
|
|
|
CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
|
|
|
|
SALOMEDS::SObject_ptr theSObject,
|
|
|
|
const GEOM::ListOfGO& theArgs,
|
|
|
|
GEOM::find_shape_method theFindMethod,
|
|
|
|
CORBA::Boolean theInheritFirstArg)
|
|
|
|
{
|
|
|
|
if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
|
|
|
if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
|
|
|
CORBA::String_var anIORso = anAttrIOR->Value();
|
|
|
|
|
|
|
|
// get Object from SObject
|
|
|
|
GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
|
|
|
|
if (CORBA::is_nil(anO))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : RestoreSubShapes
|
|
|
|
// purpose : Private method. Works only if both theObject and theSObject
|
|
|
|
// are defined, and does not check, if they correspond to each other.
|
|
|
|
//============================================================================
|
|
|
|
CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy,
|
|
|
|
GEOM::GEOM_Object_ptr theObject,
|
|
|
|
SALOMEDS::SObject_ptr theSObject,
|
|
|
|
const GEOM::ListOfGO& theArgs,
|
|
|
|
GEOM::find_shape_method theFindMethod,
|
|
|
|
CORBA::Boolean theInheritFirstArg)
|
|
|
|
{
|
|
|
|
if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Arguments to be published
|
|
|
|
GEOM::ListOfGO_var aList;
|
|
|
|
|
|
|
|
// If theArgs list is empty, we try to publish all arguments,
|
|
|
|
// otherwise publish only passed args
|
|
|
|
Standard_Integer nbArgsActual = -1; // -1 means unknown
|
|
|
|
Standard_Integer aLength = theArgs.length();
|
|
|
|
if (aLength > 0) {
|
|
|
|
aList = new GEOM::ListOfGO;
|
|
|
|
aList->length(aLength);
|
|
|
|
for (int i = 0; i < aLength; i++) {
|
|
|
|
aList[i] = theArgs[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get all arguments
|
|
|
|
aList = theObject->GetDependency();
|
|
|
|
aLength = aList->length();
|
|
|
|
nbArgsActual = aLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLength < 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (theInheritFirstArg || (nbArgsActual == 1)) {
|
|
|
|
// Do not publish argument's reflection,
|
|
|
|
// but only reconstruct its published sub-shapes
|
|
|
|
|
|
|
|
GEOM::GEOM_Object_var anArgO = aList[0];
|
|
|
|
CORBA::String_var anIOR = _orb->object_to_string(anArgO);
|
|
|
|
SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
|
|
|
|
|
|
|
|
GEOM::ListOfGO_var aParts =
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
|
|
|
|
|
|
|
|
// set the color of the transformed shape to the color of initial shape
|
|
|
|
theObject->SetColor(aList[0]->GetColor());
|
|
|
|
|
|
|
|
return (aParts->length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get interface, containing method, which we will use to reconstruct sub-shapes
|
|
|
|
GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
|
|
|
|
GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
|
|
|
|
|
|
|
|
// Reconstruct arguments and tree of sub-shapes of the arguments
|
|
|
|
CORBA::String_var anIOR;
|
|
|
|
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
|
|
|
|
for (Standard_Integer i = 0; i < aLength; i++)
|
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var anArgO = aList[i];
|
|
|
|
if (!CORBA::is_nil(anArgO)) {
|
|
|
|
anIOR = _orb->object_to_string(anArgO);
|
|
|
|
SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
|
|
|
|
TCollection_AsciiString anArgName;
|
|
|
|
if (CORBA::is_nil(anArgSO)) {
|
|
|
|
anArgName = "arg_";
|
|
|
|
anArgName += TCollection_AsciiString(i);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
anArgName = anArgSO->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a sub-shape of theObject in place of the argument
|
|
|
|
GEOM::GEOM_Object_var aSubO;
|
|
|
|
switch (theFindMethod) {
|
|
|
|
case GEOM::FSM_GetInPlace:
|
|
|
|
{
|
|
|
|
// Use GetInPlace
|
|
|
|
aSubO = aShapesOp->GetInPlace(theObject, anArgO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_Transformed:
|
|
|
|
{
|
|
|
|
// transformation, cannot use GetInPlace, operate with indices
|
|
|
|
GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
|
|
|
|
if (anIDs->length() > 1) {
|
|
|
|
// group
|
|
|
|
aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
|
|
|
|
if (!CORBA::is_nil(aSubO))
|
|
|
|
aGroupOp->UnionIDs(aSubO, anIDs);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// single sub-shape
|
|
|
|
aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetSame:
|
|
|
|
{
|
|
|
|
// Use GetSame
|
|
|
|
aSubO = aShapesOp->GetSame(theObject, anArgO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetShapesOnShape:
|
|
|
|
{
|
|
|
|
// Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
|
|
|
|
aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
|
|
|
|
(short)GEOM::SOLID, GEOM::ST_ONIN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetInPlaceByHistory:
|
|
|
|
{
|
|
|
|
// Use GetInPlaceByHistory
|
|
|
|
aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CORBA::is_nil(aSubO)) {
|
|
|
|
// Publish the sub-shape
|
|
|
|
TCollection_AsciiString aSubName ("from_");
|
|
|
|
aSubName += anArgName;
|
|
|
|
SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
|
|
|
|
aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
|
|
|
|
// Restore color
|
|
|
|
aSubO->SetColor(anArgO->GetColor());
|
|
|
|
|
|
|
|
if (!CORBA::is_nil(anArgSO)) {
|
|
|
|
// Restore published sub-shapes of the argument
|
|
|
|
if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
|
|
|
|
// pass theObject, because only it has the history
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
|
|
|
|
else
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // GetInPlace failed, try to build from published parts
|
|
|
|
if (!CORBA::is_nil(anArgSO)) {
|
|
|
|
SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
|
|
|
|
|
|
|
|
// Restore published sub-shapes of the argument
|
|
|
|
GEOM::ListOfGO_var aParts =
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
|
|
|
|
|
|
|
|
if (aParts->length() > 0) {
|
|
|
|
// try to build an argument from a set of its sub-shapes,
|
|
|
|
// that published and will be reconstructed
|
|
|
|
if (aParts->length() > 1) {
|
|
|
|
aSubO = aShapesOp->MakeCompound(aParts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSubO = aParts[0];
|
|
|
|
}
|
|
|
|
if (!CORBA::is_nil(aSubO)) {
|
|
|
|
// Publish the sub-shape
|
|
|
|
TCollection_AsciiString aSubName ("from_parts_of_");
|
|
|
|
aSubName += anArgName;
|
|
|
|
aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
|
|
|
|
// Restore color
|
|
|
|
aSubO->SetColor(anArgO->GetColor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// remove created aSubSO, because no parts have been found
|
|
|
|
aStudyBuilder->RemoveObject(aSubSO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // try to build from published parts
|
|
|
|
}
|
|
|
|
} // process arguments
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : RestoreSubShapesOneLevel
|
|
|
|
// purpose : Private method
|
|
|
|
//============================================================================
|
|
|
|
GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
|
|
|
|
SALOMEDS::SObject_ptr theOldSO,
|
|
|
|
SALOMEDS::SObject_ptr theNewSO,
|
|
|
|
GEOM::GEOM_Object_ptr theNewO,
|
|
|
|
GEOM::find_shape_method theFindMethod)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
|
|
|
|
if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
|
|
|
|
CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO))
|
|
|
|
return aParts._retn();
|
|
|
|
|
|
|
|
SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
|
|
|
|
|
|
|
|
// Get interface, containing method, which we will use to reconstruct sub-shapes
|
|
|
|
GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
|
|
|
|
GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
|
|
|
|
|
|
|
|
// Reconstruct published sub-shapes
|
|
|
|
SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
|
|
|
|
|
|
|
|
int aLen = 0;
|
|
|
|
for (it->Init(); it->More(); it->Next()) {
|
|
|
|
aLen++;
|
|
|
|
}
|
|
|
|
aParts->length(aLen);
|
|
|
|
|
|
|
|
for (it->Init(); it->More(); it->Next()) {
|
|
|
|
SALOMEDS::SObject_var anOldSubSO = it->Value();
|
|
|
|
|
|
|
|
TCollection_AsciiString anArgName = anOldSubSO->GetName();
|
|
|
|
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
|
|
|
if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
|
|
|
|
SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
|
|
|
GEOM::GEOM_Object_var anOldSubO =
|
|
|
|
GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
|
|
|
|
if (!CORBA::is_nil(anOldSubO)) {
|
|
|
|
// Find a sub-shape of theNewO in place of anOldSubO
|
|
|
|
GEOM::GEOM_Object_var aNewSubO;
|
|
|
|
switch (theFindMethod) {
|
|
|
|
case GEOM::FSM_GetInPlace:
|
|
|
|
{
|
|
|
|
// Use GetInPlace
|
|
|
|
aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_Transformed:
|
|
|
|
{
|
|
|
|
// transformation, cannot use GetInPlace, operate with indices
|
|
|
|
GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
|
|
|
|
if (anIDs->length() > 1) {
|
|
|
|
// group
|
|
|
|
aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
|
|
|
|
if (!CORBA::is_nil(aNewSubO))
|
|
|
|
aGroupOp->UnionIDs(aNewSubO, anIDs);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// single sub-shape
|
|
|
|
aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetSame:
|
|
|
|
{
|
|
|
|
// Use GetSame
|
|
|
|
aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetShapesOnShape:
|
|
|
|
{
|
|
|
|
// Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
|
|
|
|
aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
|
|
|
|
(short)GEOM::SOLID, GEOM::ST_ONIN);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOM::FSM_GetInPlaceByHistory:
|
|
|
|
{
|
|
|
|
// Use GetInPlaceByHistory
|
|
|
|
aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CORBA::is_nil(aNewSubO)) {
|
|
|
|
// add the part to the list
|
|
|
|
aParts[i] = aNewSubO;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// Publish the sub-shape
|
|
|
|
TCollection_AsciiString aSubName ("from_");
|
|
|
|
aSubName += anArgName;
|
|
|
|
SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
|
|
|
|
aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
|
|
|
|
// Restore color
|
|
|
|
aNewSubO->SetColor(anOldSubO->GetColor());
|
|
|
|
|
|
|
|
// Restore published sub-shapes of the argument
|
|
|
|
if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
|
|
|
|
// pass the main shape as Object, because only it has the history
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
|
|
|
|
else
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
|
|
|
|
}
|
|
|
|
else { // GetInPlace failed, try to build from published parts
|
|
|
|
SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
|
|
|
|
|
|
|
|
// Restore published sub-shapes of the argument
|
|
|
|
GEOM::ListOfGO_var aParts =
|
|
|
|
RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
|
|
|
|
|
|
|
|
if (aParts->length() > 0) {
|
|
|
|
// try to build an object from a set of its sub-shapes,
|
|
|
|
// that published and will be reconstructed
|
|
|
|
if (aParts->length() > 1) {
|
|
|
|
aNewSubO = aShapesOp->MakeCompound(aParts);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aNewSubO = aParts[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CORBA::is_nil(aNewSubO)) {
|
|
|
|
// add the part to the list
|
|
|
|
aParts[i] = aNewSubO;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// Publish the sub-shape
|
|
|
|
TCollection_AsciiString aSubName = "from_parts_of_";
|
|
|
|
aSubName += anArgName;
|
|
|
|
aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
|
|
|
|
// Restore color
|
|
|
|
aNewSubO->SetColor(anOldSubO->GetColor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// remove created aSubSO, because no parts have been found
|
|
|
|
aStudyBuilder->RemoveObject(aNewSubSO);
|
|
|
|
}
|
|
|
|
} // try to build from published parts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // iterate on published sub-shapes
|
|
|
|
|
|
|
|
aParts->length(i);
|
|
|
|
return aParts._retn();
|
|
|
|
}
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
2005-08-18 12:15:31 +06:00
|
|
|
// function : register()
|
2004-12-01 15:39:14 +05:00
|
|
|
// purpose : register 'name' in 'name_service'
|
|
|
|
//============================================================================
|
|
|
|
void GEOM_Gen_i::register_name(char * name)
|
|
|
|
{
|
2008-03-07 12:45:34 +05:00
|
|
|
GEOM::GEOM_Gen_var g = _this();
|
|
|
|
name_service->Register(g, name);
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : Undo
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
|
|
|
|
{
|
|
|
|
_impl->Undo(theStudyID);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : Redo
|
|
|
|
// purpose :
|
|
|
|
//============================================================================
|
|
|
|
void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
|
|
|
|
{
|
|
|
|
_impl->Redo(theStudyID);
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIBasicOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
2008-03-07 12:45:34 +05:00
|
|
|
//transfer reference on engine
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM_IBasicOperations_i* aServant =
|
|
|
|
new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetITransformOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_ITransformOperations_i* aServant =
|
|
|
|
new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetI3DPrimOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_I3DPrimOperations_i* aServant =
|
|
|
|
new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIShapesOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IShapesOperations_i* aServant =
|
|
|
|
new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIBlocksOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IBlocksOperations_i* aServant =
|
|
|
|
new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIBooleanOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IBooleanOperations_i* aServant =
|
|
|
|
new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetICurvesOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_ICurvesOperations_i* aServant =
|
|
|
|
new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetILocalOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_ILocalOperations_i* aServant =
|
|
|
|
new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIHealingOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::IHealingOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IHealingOperations_i* aServant =
|
|
|
|
new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIInsertOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IInsertOperations_i* aServant =
|
|
|
|
new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIMeasureOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IMeasureOperations_i* aServant =
|
|
|
|
new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
// function : GetIGroupOperations
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//============================================================================
|
|
|
|
GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
|
|
|
|
throw ( SALOME::SALOME_Exception )
|
|
|
|
{
|
|
|
|
Unexpect aCatch(SALOME_SalomeException);
|
|
|
|
MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
GEOM_IGroupOperations_i* aServant =
|
|
|
|
new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
|
|
|
|
|
2005-08-18 12:15:31 +06:00
|
|
|
// activate the CORBA servant
|
2004-12-01 15:39:14 +05:00
|
|
|
GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
|
|
|
|
return operations._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*!
|
|
|
|
* AddSubShape
|
|
|
|
*/
|
|
|
|
//=============================================================================
|
2005-06-02 13:17:09 +06:00
|
|
|
GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
|
|
|
|
const GEOM::ListOfLong& theIndices)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
|
|
|
|
Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
|
|
|
|
if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
|
2005-08-18 12:15:31 +06:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
|
|
|
|
for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
|
|
|
|
|
2005-06-02 13:17:09 +06:00
|
|
|
Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
|
2004-12-01 15:39:14 +05:00
|
|
|
if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
|
|
|
|
|
|
|
|
TCollection_AsciiString anEntry;
|
|
|
|
TDF_Tool::Entry(anObject->GetEntry(), anEntry);
|
|
|
|
return GetObject(anObject->GetDocID(), anEntry.ToCString());
|
|
|
|
}
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*!
|
|
|
|
* RemoveObject
|
|
|
|
*/
|
|
|
|
//=============================================================================
|
2005-08-18 12:15:31 +06:00
|
|
|
void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2009-02-13 17:16:39 +05:00
|
|
|
CORBA::String_var anEntry = theObject->GetEntry();
|
|
|
|
Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
|
2004-12-01 15:39:14 +05:00
|
|
|
if (anObject.IsNull()) return;
|
|
|
|
_impl->RemoveObject(anObject);
|
2005-08-18 12:15:31 +06:00
|
|
|
return;
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : GetStringFromIOR()
|
|
|
|
// purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
|
|
|
|
//=================================================================================
|
|
|
|
char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
|
|
|
|
return _orb->object_to_string(theObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : GetIORFromString()
|
|
|
|
// purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
|
|
|
|
//=================================================================================
|
|
|
|
GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
|
|
|
|
GEOM::GEOM_Object_var aGeomObject;
|
|
|
|
if(strcmp(stringIOR,"") != 0){
|
|
|
|
CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
|
|
|
|
if(!CORBA::is_nil(anObject))
|
2005-08-18 12:15:31 +06:00
|
|
|
aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
2005-08-18 12:15:31 +06:00
|
|
|
return aGeomObject._retn();
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : GetObject()
|
2005-08-18 12:15:31 +06:00
|
|
|
// purpose :
|
2004-12-01 15:39:14 +05:00
|
|
|
//=================================================================================
|
2005-08-18 12:15:31 +06:00
|
|
|
GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var obj;
|
|
|
|
Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
|
2005-08-18 12:15:31 +06:00
|
|
|
if (handle_object.IsNull()) return NULL;
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
TCollection_AsciiString stringIOR = handle_object->GetIOR();
|
2005-08-18 12:15:31 +06:00
|
|
|
if (stringIOR.Length() > 1) {
|
2004-12-01 15:39:14 +05:00
|
|
|
CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
|
2005-08-18 12:15:31 +06:00
|
|
|
if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
|
|
|
|
return obj._retn();
|
|
|
|
}
|
|
|
|
|
|
|
|
GEOM::GEOM_Gen_ptr engine = _this();
|
|
|
|
GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
obj = servant->_this();
|
2008-03-07 12:45:34 +05:00
|
|
|
CORBA::String_var objStr = _orb->object_to_string(obj);
|
|
|
|
TCollection_AsciiString anAscii( (char *)objStr.in() );
|
|
|
|
handle_object->SetIOR( anAscii );
|
2005-08-18 12:15:31 +06:00
|
|
|
return obj._retn();
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
|
2009-02-13 17:16:39 +05:00
|
|
|
//=================================================================================
|
|
|
|
// function : hasObjectInfo()
|
|
|
|
// purpose : shows if module provides information for its objects
|
|
|
|
//=================================================================================
|
|
|
|
bool GEOM_Gen_i::hasObjectInfo()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : getObjectInfo()
|
|
|
|
// purpose : returns an information for a given object by its entry
|
|
|
|
//=================================================================================
|
|
|
|
char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
|
|
|
|
{
|
|
|
|
GEOM::GEOM_Object_var aGeomObject;
|
|
|
|
|
|
|
|
CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
|
|
|
|
SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
|
|
|
|
SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
|
|
|
|
SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
|
|
|
|
SALOMEDS::SObject_var aResultSObj;
|
|
|
|
if (aSObj->ReferencedObject(aResultSObj))
|
|
|
|
aSObj = aResultSObj;
|
|
|
|
|
|
|
|
SALOMEDS::GenericAttribute_var anAttr;
|
|
|
|
if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
|
|
|
|
SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
|
|
|
|
CORBA::String_var aVal = anIOR->Value();
|
|
|
|
CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
|
|
|
|
aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* aTypeInfo = "Object";
|
|
|
|
if ( !aGeomObject->_is_nil() ) {
|
|
|
|
GEOM::GEOM_IKindOfShape::shape_kind aKind;
|
|
|
|
GEOM::ListOfLong_var anInts;
|
|
|
|
GEOM::ListOfDouble_var aDbls;
|
|
|
|
|
|
|
|
GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
|
|
|
|
aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
|
|
|
|
|
|
|
|
if ( anOp->IsDone() ) {
|
|
|
|
switch ( aKind ) {
|
|
|
|
case GEOM::GEOM_IKindOfShape::COMPOUND:
|
|
|
|
aTypeInfo = "Compound";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::COMPSOLID:
|
|
|
|
aTypeInfo = "CompSolid";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::SHELL:
|
|
|
|
aTypeInfo = "Shell";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::WIRE:
|
|
|
|
if ( anInts[0] == 1 )
|
|
|
|
aTypeInfo = "Closed Wire";
|
|
|
|
else if ( anInts[0] == 2 )
|
|
|
|
aTypeInfo = "Opened Wire";
|
|
|
|
else
|
|
|
|
aTypeInfo = "Wire";
|
|
|
|
break;
|
|
|
|
// SOLIDs
|
|
|
|
case GEOM::GEOM_IKindOfShape::SPHERE:
|
|
|
|
aTypeInfo = "Sphere";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::CYLINDER:
|
|
|
|
aTypeInfo = "Cylinder";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::BOX:
|
|
|
|
case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
|
|
|
|
aTypeInfo = "Box";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::TORUS:
|
|
|
|
aTypeInfo = "Torus";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::CONE:
|
|
|
|
aTypeInfo = "Cone";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::POLYHEDRON:
|
|
|
|
aTypeInfo = "Polyhedron";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::SOLID:
|
|
|
|
aTypeInfo = "Solid";
|
|
|
|
break;
|
|
|
|
// FACEs
|
|
|
|
case GEOM::GEOM_IKindOfShape::SPHERE2D:
|
|
|
|
aTypeInfo = "Spherical Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::CYLINDER2D:
|
|
|
|
aTypeInfo = "Cylindrical Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::TORUS2D:
|
|
|
|
aTypeInfo = "Toroidal Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::CONE2D:
|
|
|
|
aTypeInfo = "Conical Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
|
|
|
|
aTypeInfo = "Disk";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
|
|
|
|
aTypeInfo = "Elliptical Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::POLYGON:
|
|
|
|
aTypeInfo = "Polygon";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::PLANE:
|
|
|
|
aTypeInfo = "Plane";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::PLANAR:
|
|
|
|
aTypeInfo = "Planar Face";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::FACE:
|
|
|
|
aTypeInfo = "Face";
|
|
|
|
break;
|
|
|
|
// EDGEs
|
|
|
|
case GEOM::GEOM_IKindOfShape::CIRCLE:
|
|
|
|
aTypeInfo = "Circle";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
|
|
|
|
aTypeInfo = "Ark";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::ELLIPSE:
|
|
|
|
aTypeInfo = "Ellipse";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
|
|
|
|
aTypeInfo = "Arc Ellipse";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::LINE:
|
|
|
|
aTypeInfo = "Line";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::SEGMENT:
|
|
|
|
aTypeInfo = "Segment";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::EDGE:
|
|
|
|
aTypeInfo = "Edge";
|
|
|
|
break;
|
|
|
|
case GEOM::GEOM_IKindOfShape::VERTEX:
|
|
|
|
aTypeInfo = "Vertex";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char anInfo [strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo)];
|
|
|
|
sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
|
|
|
|
|
|
|
|
return CORBA::string_dup(anInfo);
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
//=====================================================================================
|
|
|
|
// EXPORTED METHODS
|
|
|
|
//=====================================================================================
|
|
|
|
extern "C"
|
|
|
|
{
|
2008-03-07 12:45:34 +05:00
|
|
|
GEOM_I_EXPORT
|
2004-12-01 15:39:14 +05:00
|
|
|
PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
|
2005-08-18 12:15:31 +06:00
|
|
|
PortableServer::POA_ptr poa,
|
2004-12-01 15:39:14 +05:00
|
|
|
PortableServer::ObjectId * contId,
|
2005-08-18 12:15:31 +06:00
|
|
|
const char *instanceName,
|
2004-12-01 15:39:14 +05:00
|
|
|
const char * interfaceName)
|
|
|
|
{
|
|
|
|
GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
|
2008-03-07 12:45:34 +05:00
|
|
|
// Don't understand the reason of this register ????
|
|
|
|
// myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
|
2005-08-18 12:15:31 +06:00
|
|
|
return myGEOM_Gen_i->getId();
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
}
|