1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_Gen_i.hh"
29 #include "GEOM_Object_i.hh"
35 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "GEOM_Object_i.hh"
41 #include "GEOM_Object.hxx"
42 #include "GEOM_Function.hxx"
43 #include "GEOM_ISubShape.hxx"
44 #include <GEOM_PythonDump.hxx>
45 #include "GEOMImpl_Types.hxx"
46 #include "GEOMImpl_CopyDriver.hxx"
49 #include <BRep_Builder.hxx>
50 #include <BRepTools.hxx>
51 #include <TDF_Label.hxx>
52 #include <TDF_Tool.hxx>
53 #include <TDF_ChildIDIterator.hxx>
54 #include <TNaming_NamedShape.hxx>
55 #include <TDataStd_Name.hxx>
56 #include <TCollection_AsciiString.hxx>
57 #include <TColStd_HArray1OfInteger.hxx>
58 #include <TopAbs_ShapeEnum.hxx>
59 //#include <TopTools_IndexedMapOfShape.hxx>
63 #include "SALOMEDS_Tool.hxx"
65 //============================================================================
66 // function : GEOM_Gen_i()
67 // purpose : constructor to be called for servant creation.
68 //============================================================================
69 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
70 PortableServer::POA_ptr poa,
71 PortableServer::ObjectId * contId,
72 const char *instanceName,
73 const char *interfaceName) :
74 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
77 _id = _poa->activate_object(_thisObj);
78 name_service = new SALOME_NamingService(_orb);
80 _impl = new ::GEOMImpl_Gen;
82 //PAL10867: disable signals catching with "noexcepthandler" option
83 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
84 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
86 //work around PAL12004, PAL12628
87 //OSD::SetSignal( true );
91 char* envDisableFPE = getenv("DISABLE_FPE");
92 if (envDisableFPE && atoi(envDisableFPE))
97 OSD::SetSignal( raiseFPE );
101 //============================================================================
102 // function : ~GEOM_Gen_i()
103 // purpose : destructor
104 //============================================================================
105 GEOM_Gen_i::~GEOM_Gen_i() {
111 //============================================================================
112 // function : IORToLocalPersistentID()
114 //============================================================================
115 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
116 const char* IORString,
117 CORBA::Boolean isMultiFile,
118 CORBA::Boolean isASCII)
120 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
121 if (!CORBA::is_nil(anObject)) {
122 return CORBA::string_dup(anObject->GetEntry());
128 //============================================================================
129 // function : LocalPersistentIDToIOR()
130 // purpose : Create/Load CORBA object from a persistent ref (an entry)
131 // : Used when a study is loaded
132 // : The IOR (IORName) of object created is returned
133 //============================================================================
134 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
135 const char* aLocalPersistentID,
136 CORBA::Boolean isMultiFile,
137 CORBA::Boolean isASCII)
139 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
141 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
142 TCollection_AsciiString anEntry;
143 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
144 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
146 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
147 return CORBA::string_dup(aPersRefString);
150 //============================================================================
151 // function : CanPublishInStudy
153 //============================================================================
154 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
156 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
157 return !(anObject->_is_nil());
161 //============================================================================
162 // function : PublishInStudy
164 //============================================================================
165 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
166 SALOMEDS::SObject_ptr theSObject,
167 CORBA::Object_ptr theObject,
168 const char* theName) throw (SALOME::SALOME_Exception)
170 Unexpect aCatch(SALOME_SalomeException);
171 SALOMEDS::SObject_var aResultSO;
172 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
173 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
174 if(aShape->_is_nil()) return aResultSO;
176 SALOMEDS::GenericAttribute_var anAttr;
177 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
179 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
180 if (aFather->_is_nil()) {
181 aFather = aStudyBuilder->NewComponent("GEOM");
182 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
183 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
184 aName->SetValue("Geometry");
185 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
186 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
187 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
189 if (aFather->_is_nil()) return aResultSO;
191 if (CORBA::is_nil(theSObject)) {
192 aResultSO = aStudyBuilder->NewObject(aFather);
194 if (!theSObject->ReferencedObject(aResultSO))
195 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
196 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
198 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
199 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
200 //char *aGeomObjIOR = _orb->object_to_string(theObject);
201 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
202 //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
203 anIOR->SetValue(aGeomObjIOR);
205 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
206 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
207 TCollection_AsciiString aShapeName("Shape_");
209 if ( aShape->GetType() == GEOM_GROUP ) {
210 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
211 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
213 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
214 aShapeName = "Group_Of_Vertices_";
217 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
218 aShapeName = "Group_Of_Edges_";
221 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
222 aShapeName = "Group_Of_Faces_";
225 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
226 aShapeName = "Group_Of_Solids_";
229 } else if ( aShape->GetType() == GEOM_MARKER ) {
230 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
231 aShapeName = "LocalCS_";
232 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
233 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
234 aShapeName = "Compound_";
235 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
236 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
237 aShapeName = "Compsolid_";
238 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
239 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
240 aShapeName = "Solid_";
241 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
242 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
243 aShapeName = "Shell_";
244 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
245 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
246 aShapeName = "Face_";
247 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
248 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
249 aShapeName = "Wire_";
250 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
251 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
252 aShapeName = "Edge_";
253 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
254 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
255 aShapeName = "Vertex_";
257 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
258 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
260 // try to find existed name for current shape
261 bool HasName = false;
262 // recieve current TopoDS shape
263 CORBA::String_var entry = aShape->GetEntry();
264 Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
265 TopoDS_Shape TopoSh = aGShape->GetValue();
266 // find label of main shape
267 GEOM::GEOM_Object_var aMainShVar = aShape;
268 GEOM::GEOM_Object_ptr aMainSh = aMainShVar._retn();
269 while( !aMainSh->IsMainShape() ) {
270 aMainSh = aMainSh->GetMainShape();
272 entry = aMainSh->GetEntry();
273 Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
274 TDF_Label aMainLbl = anObj->GetEntry();
275 // check all named shapes using iterator
276 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
277 for(; anIt.More(); anIt.Next()) {
278 Handle(TNaming_NamedShape) anAttr =
279 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
280 if(anAttr.IsNull()) continue;
281 TopoDS_Shape S = anAttr->Get();
282 if( !S.IsEqual(TopoSh) ) continue;
283 TDF_Label L = anAttr->Label();
284 Handle(TDataStd_Name) aName;
285 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
286 aShapeName = aName->Get();
292 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
293 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
294 // of objects in the study, but compute a number of objects with the same prefix
295 // and build a new name as Prefix_N+1
296 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
297 int i = 0; // (WITH EMPTY NEW NAME)
298 SALOMEDS::SObject_var obj;
299 TCollection_AsciiString aNewShapeName;
301 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
302 obj = theStudy->FindObject( aNewShapeName.ToCString() );
304 while ( !obj->_is_nil() );
305 aShapeName = aNewShapeName;
307 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
308 aShapeName = TCollection_AsciiString((char*)theName);
311 //Set the study entry as a name of the published GEOM_Object
312 aShape->SetStudyEntry(aResultSO->GetID());
314 //Set a name of the added shape
315 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
316 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
317 aNameAttrib->SetValue(aShapeName.ToCString());
319 //Set NoteBook variables used in the object creation
320 TCollection_AsciiString aVars;
321 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
322 for(int i = 0, n = aSections->length(); i < n; i++) {
323 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
324 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
325 if(theStudy->IsVariable(aListOfVars[j].in()))
326 aVars += TCollection_AsciiString(aListOfVars[j].in());
333 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
334 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
335 aStringAttrib->SetValue(aVars.ToCString());
337 //Set a name of the GEOM object
338 aShape->SetName(theName);
340 return aResultSO._retn();
344 //============================================================================
345 // function : CreateAndPublishGroup
346 // purpose : auxilary for PublishNamedShapesInStudy
347 //============================================================================
348 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
349 GEOM::GEOM_Object_var theMainShape,
350 const TopTools_IndexedMapOfShape& anIndices,
351 const TopTools_SequenceOfShape& SeqS,
352 const TColStd_SequenceOfAsciiString& SeqN,
353 const Standard_CString& GrName,
354 GEOM::ListOfGO_var aResList)
356 CORBA::String_var entry = theMainShape->GetEntry();
357 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
358 Handle(TColStd_HArray1OfInteger) anArray;
359 if(SeqS.Length()>0) {
361 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
362 GEOM::GEOM_Object_ptr GrObj =
363 GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
364 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
366 Handle(GEOM_Object) anObj;
367 for(int i=1; i<=SeqS.Length(); i++) {
368 TopoDS_Shape aValue = SeqS.Value(i);
369 anArray = new TColStd_HArray1OfInteger(1,1);
370 Standard_Integer anIndex = anIndices.FindIndex(aValue);
371 anArray->SetValue(1, anIndex);
372 anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
373 if (anObj.IsNull()) continue;
374 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
375 if (aFunction.IsNull()) continue;
376 GEOM_ISubShape aSSI(aFunction);
377 aSSI.SetMainShape(aMainShape->GetLastFunction());
378 aSSI.SetIndices(anArray);
379 aFunction->SetValue(aValue);
380 GOp->UnionIDs(GrObj, anIndex);
381 SALOMEDS::SObject_var aResultSO;
382 TCollection_AsciiString anEntry;
383 TDF_Tool::Entry(anObj->GetEntry(),anEntry);
384 GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
385 AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
391 //============================================================================
392 // function : PublishNamedShapesInStudy
394 //============================================================================
395 GEOM::ListOfGO* GEOM_Gen_i::
396 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
397 //SALOMEDS::SObject_ptr theSObject,
398 CORBA::Object_ptr theObject)
400 //Unexpect aCatch(SALOME_SalomeException);
401 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
403 //CORBA::Object_var theObject = theSObject->GetObject();
404 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
405 if(theMainShape->_is_nil()) return aResList._retn();
407 CORBA::String_var entry = theMainShape->GetEntry();
408 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
409 if (aMainShape.IsNull()) return aResList._retn();
410 TopoDS_Shape MainSh = aMainShape->GetValue();
412 TDF_Label aMainLbl = aMainShape->GetEntry();
413 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
414 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
415 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
416 for(; anIt.More(); anIt.Next()) {
417 Handle(TNaming_NamedShape) anAttr =
418 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
419 if(anAttr.IsNull()) continue;
420 TopoDS_Shape S = anAttr->Get();
421 TDF_Label L = anAttr->Label();
422 //if(S.IsEqual(MainSh)) continue;
423 Handle(TDataStd_Name) aName;
424 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
425 TCollection_ExtendedString EName = aName->Get();
426 if(S.ShapeType()==TopAbs_SOLID) {
428 SolidSeqN.Append(aName->Get());
430 else if(S.ShapeType()==TopAbs_FACE) {
432 FaceSeqN.Append(aName->Get());
434 else if(S.ShapeType()==TopAbs_EDGE) {
436 EdgeSeqN.Append(aName->Get());
438 else if(S.ShapeType()==TopAbs_VERTEX) {
440 VertSeqN.Append(aName->Get());
445 TopTools_IndexedMapOfShape anIndices;
446 TopExp::MapShapes(MainSh, anIndices);
448 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
449 "Group_Of_Named_Solids", aResList);
451 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
452 "Group_Of_Named_Faces", aResList);
454 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
455 "Group_Of_Named_Edges", aResList);
457 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
458 "Group_Of_Named_Vertices", aResList);
460 return aResList._retn();
464 //============================================================================
466 // purpose : save OCAF/Geom document
467 //============================================================================
468 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
471 SALOMEDS::TMPFile_var aStreamFile;
472 // Get a temporary directory to store a file
473 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
475 // OCCT BUG: cannot save a document (in current folder)
476 // if directory name is empty
477 if (aTmpDir.size() == 0) {
485 // Create a list to store names of created files
486 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
488 // Prepare a file name to open
489 TCollection_AsciiString aNameWithExt("");
491 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
492 (theComponent->GetStudy()->URL())).c_str());
493 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
494 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
495 // Build a full file name of temporary file
496 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
497 // Save GEOM component in this file
498 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
499 // Conver a file to the byte stream
500 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
501 // Remove the created file and tmp directory
502 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
504 // Return the created byte stream
505 return aStreamFile._retn();
509 //============================================================================
510 // function : SaveASCII()
512 //============================================================================
513 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
516 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
517 return aStreamFile._retn();
521 //============================================================================
524 //============================================================================
525 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
526 const SALOMEDS::TMPFile& theStream,
530 if (theStream.length() <= 9) {
531 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
535 // Get a temporary directory for a file
536 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
538 // OCCT BUG: cannot load a document (from current folder)
539 // if directory name is empty
540 if (aTmpDir.size() == 0) {
548 // Conver the byte stream theStream to a file and place it in tmp directory
549 SALOMEDS::ListOfFileNames_var aSeq =
550 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
552 // Prepare a file name to open
553 TCollection_AsciiString aNameWithExt("");
555 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
556 (theComponent->GetStudy()->URL())).c_str());
557 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
558 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
561 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
563 // Remove the created file and tmp directory
564 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
566 SALOMEDS::Study_var Study = theComponent->GetStudy();
567 TCollection_AsciiString name (Study->Name());
573 //============================================================================
574 // function : LoadASCII()
576 //============================================================================
577 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
578 const SALOMEDS::TMPFile& theStream,
581 return Load(theComponent, theStream, theURL, isMultiFile);
585 //============================================================================
586 // function : Close()
588 //============================================================================
589 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
591 _impl->Close(theComponent->GetStudy()->StudyId());
594 //============================================================================
595 // function : CanCopy()
597 //============================================================================
598 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
599 // Try to retrieve known by Geometry component GEOM_Object by given IOR
600 SALOMEDS::GenericAttribute_var anAttr;
601 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
603 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
605 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
606 // If the object is null one it can't be copied: return false
607 if (anObject->_is_nil()) return false;
611 //============================================================================
612 // function : CopyFrom()
614 //============================================================================
615 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
617 // Declare a sequence of the byte to store the copied object
618 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
620 // Try to get GEOM_Object object by given SObject
621 SALOMEDS::GenericAttribute_var anAttr;
622 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
623 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
624 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
625 if (anObject->_is_nil()) return aStreamFile._retn();
627 aStreamFile = anObject->GetShapeStream();
629 // Assign an ID the type of GEOM_Object
630 theObjectID = anObject->GetType();
632 // Return created TMPFile
633 return aStreamFile._retn();
636 //============================================================================
637 // function : CanPaste()
639 //============================================================================
640 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
641 // The Geometry component can paste only objects copied by Geometry component
642 // and with the object type = 1
643 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
647 //============================================================================
648 // function : PasteInto()
650 //============================================================================
651 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
652 CORBA::Long theObjectID,
653 SALOMEDS::SObject_ptr theObject) {
654 // Find the current Study and StudyBuilder
655 SALOMEDS::Study_var aStudy = theObject->GetStudy();
656 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
658 // Retrieve a TopoDS_Shape from byte stream
659 TopoDS_Shape aTopology;
660 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
661 BRep_Builder aBuilder;
663 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
664 } catch (Standard_Failure) {
668 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
669 SALOMEDS::SObject_var aNewSO;
670 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
671 aNewSO = aStudyBuilder->NewObject(theObject);
672 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
675 //Create a new GEOM_Object
676 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
677 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
678 aFunction->SetValue(aTopology);
680 TCollection_AsciiString anEntry;
681 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
682 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
684 //Set the study entry of the published GEOM_Object
685 obj->SetStudyEntry(aNewSO->GetID());
687 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
688 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
689 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
690 CORBA::String_var objStr = _orb->object_to_string(obj);
691 anIOR->SetValue(objStr.in());
693 // Return the created in the Study SObject
694 return aNewSO._retn();
697 //============================================================================
698 // function : ComponentDataType()
700 //============================================================================
701 char* GEOM_Gen_i::ComponentDataType()
703 return CORBA::string_dup("GEOM");
706 //============================================================================
707 // function : AddInStudy
709 //============================================================================
710 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
711 GEOM::GEOM_Object_ptr theObject,
713 GEOM::GEOM_Object_ptr theFather)
715 SALOMEDS::SObject_var aResultSO;
716 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
718 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
719 CORBA::String_var IOR;
721 if(!theFather->_is_nil()) {
722 IOR = _orb->object_to_string(theFather);
723 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
724 if(aFatherSO->_is_nil()) return aResultSO._retn();
725 aResultSO = aStudyBuilder->NewObject(aFatherSO);
726 //aStudyBuilder->Addreference(aResultSO, aResultSO);
729 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
730 if(aResultSO->_is_nil()) return aResultSO._retn();
732 GEOM::ListOfGO_var aList = theObject->GetDependency();
733 Standard_Integer aLength = aList->length();
734 if(aLength < 1) return aResultSO._retn();
736 //Publish the arguments
737 for(Standard_Integer i = 0; i< aLength; i++) {
738 GEOM::GEOM_Object_var anObject = aList[i];
739 if(anObject->_is_nil()) continue;
740 IOR = _orb->object_to_string(anObject);
741 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
742 if(aSO->_is_nil()) continue;
743 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
744 aStudyBuilder->Addreference(aSubSO, aSO);
747 return aResultSO._retn();
750 //============================================================================
751 // function : RestoreSubShapesO
752 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
753 // To be used from python scripts out of geompy.addToStudy (non-default usage)
754 //============================================================================
755 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
756 GEOM::GEOM_Object_ptr theObject,
757 const GEOM::ListOfGO& theArgs,
758 GEOM::find_shape_method theFindMethod,
759 CORBA::Boolean theInheritFirstArg)
761 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
762 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
763 return aParts._retn();
765 // find SObject in the study if it is already published
766 CORBA::String_var anIORo = _orb->object_to_string(theObject);
767 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
768 //PTv, IMP 0020001, The salome object <aSO>
769 // is not obligatory in case of invokation from script
770 // if (CORBA::is_nil(aSO))
771 // return aParts._retn();
773 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
774 return aParts._retn();
777 //============================================================================
778 // function : RestoreSubShapesSO
779 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
780 // To be used from GUI and from geompy.addToStudy
781 //============================================================================
782 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
783 SALOMEDS::SObject_ptr theSObject,
784 const GEOM::ListOfGO& theArgs,
785 GEOM::find_shape_method theFindMethod,
786 CORBA::Boolean theInheritFirstArg)
788 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
789 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
790 return aParts._retn();
792 SALOMEDS::GenericAttribute_var anAttr;
793 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
794 return aParts._retn();
796 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
797 CORBA::String_var anIORso = anAttrIOR->Value();
799 // get Object from SObject
800 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
801 if (CORBA::is_nil(anO))
802 return aParts._retn();
804 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
805 return aParts._retn();
808 //============================================================================
809 // function : addToListOfGO
810 // purpose : static local function
811 //============================================================================
812 static void addToListOfGO( const GEOM::GEOM_Object_ptr& theObject,
813 GEOM::ListOfGO& theList )
815 const int oldLen = theList.length();
816 theList.length(oldLen + 1);
817 theList[ oldLen ] = theObject;
820 //============================================================================
821 // function : addToListOfGO
822 // purpose : static local function
823 //============================================================================
824 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
825 GEOM::ListOfGO& theTrgList )
827 const int oldLen = theTrgList.length();
828 const int srcLen = theSrcList.length();
829 theTrgList.length(oldLen + srcLen);
830 for( int i = 0; i < srcLen; i++ )
831 theTrgList[ oldLen + i ] = theSrcList[ i ];
834 //============================================================================
835 // function : RestoreSubShapes
836 // purpose : Private method. Works only if both theObject and theSObject
837 // are defined, and does not check, if they correspond to each other.
838 //============================================================================
839 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy,
840 GEOM::GEOM_Object_ptr theObject,
841 SALOMEDS::SObject_ptr theSObject,
842 const GEOM::ListOfGO& theArgs,
843 GEOM::find_shape_method theFindMethod,
844 CORBA::Boolean theInheritFirstArg)
846 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
847 //PTv, IMP 0020001, The salome object <theSObject>
848 // is not obligatory in case of invokation from script
849 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
850 return aParts._retn();
852 // Arguments to be published
853 GEOM::ListOfGO_var aList;
855 // If theArgs list is empty, we try to publish all arguments,
856 // otherwise publish only passed args
857 Standard_Integer nbArgsActual = -1; // -1 means unknown
858 Standard_Integer aLength = theArgs.length();
860 aList = new GEOM::ListOfGO;
861 aList->length(aLength);
862 for (int i = 0; i < aLength; i++) {
863 aList[i] = theArgs[i];
868 aList = theObject->GetDependency();
869 aLength = aList->length();
870 nbArgsActual = aLength;
874 return aParts._retn();
876 if (theInheritFirstArg || (nbArgsActual == 1)) {
877 // Do not publish argument's reflection,
878 // but only reconstruct its published sub-shapes
880 GEOM::GEOM_Object_var anArgO = aList[0];
881 CORBA::String_var anIOR = _orb->object_to_string(anArgO);
882 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
884 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
886 // set the color of the transformed shape to the color of initial shape
887 theObject->SetColor(aList[0]->GetColor());
890 // Get interface, containing method, which we will use to reconstruct sub-shapes
891 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
892 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
894 // Reconstruct arguments and tree of sub-shapes of the arguments
895 CORBA::String_var anIOR;
896 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
897 for (Standard_Integer i = 0; i < aLength; i++)
899 GEOM::GEOM_Object_var anArgO = aList[i];
900 if (!CORBA::is_nil(anArgO)) {
901 anIOR = _orb->object_to_string(anArgO);
902 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
903 TCollection_AsciiString anArgName;
904 if (CORBA::is_nil(anArgSO)) {
906 anArgName += TCollection_AsciiString(i);
909 anArgName = anArgSO->GetName();
912 // Find a sub-shape of theObject in place of the argument
913 GEOM::GEOM_Object_var aSubO;
914 switch (theFindMethod) {
915 case GEOM::FSM_GetInPlace:
918 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
921 case GEOM::FSM_Transformed:
923 // transformation, cannot use GetInPlace, operate with indices
924 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
925 if (anIDs->length() > 1) {
927 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
928 if (!CORBA::is_nil(aSubO))
929 aGroupOp->UnionIDs(aSubO, anIDs);
933 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
937 case GEOM::FSM_GetSame:
940 aSubO = aShapesOp->GetSame(theObject, anArgO);
943 case GEOM::FSM_GetShapesOnShape:
945 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
946 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
947 (short)GEOM::SOLID, GEOM::ST_ONIN);
950 case GEOM::FSM_GetInPlaceByHistory:
952 // Use GetInPlaceByHistory
953 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
960 if (!CORBA::is_nil(aSubO)) {
962 addToListOfGO( aSubO, aParts );
964 // Publish the sub-shape
965 SALOMEDS::SObject_var aSubSO;
966 if (!CORBA::is_nil(theSObject)) {
967 TCollection_AsciiString aSubName ("from_");
968 aSubName += anArgName;
969 aSubSO = aStudyBuilder->NewObject(theSObject);
970 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
972 aSubO->SetColor(anArgO->GetColor());
975 if (!CORBA::is_nil(anArgSO)) {
976 // Restore published sub-shapes of the argument
977 GEOM::ListOfGO_var aSubParts;
978 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
979 // pass theObject, because only it has the history
980 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
982 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
984 addToListOfGO( aSubParts, aParts );
987 else { // GetInPlace failed, try to build from published parts
988 if (!CORBA::is_nil(anArgSO)) {
989 SALOMEDS::SObject_var aSubSO;
990 if (!CORBA::is_nil(theSObject))
991 aSubSO = aStudyBuilder->NewObject(theSObject);
993 // Restore published sub-shapes of the argument
994 GEOM::ListOfGO_var aSubParts =
995 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
998 addToListOfGO( aSubParts, aParts );
1000 if (aSubParts->length() > 0) {
1001 // try to build an argument from a set of its sub-shapes,
1002 // that published and will be reconstructed
1003 if (aSubParts->length() > 1) {
1004 aSubO = aShapesOp->MakeCompound(aSubParts);
1005 // add to parts list
1006 addToListOfGO( aSubO, aParts );
1009 aSubO = aSubParts[0];
1011 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1012 // Publish the sub-shape
1013 TCollection_AsciiString aSubName ("from_parts_of_");
1014 aSubName += anArgName;
1015 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1017 aSubO->SetColor(anArgO->GetColor());
1020 else if (!CORBA::is_nil(aSubSO)) {
1021 // remove created aSubSO, because no parts have been found
1022 aStudyBuilder->RemoveObject(aSubSO);
1025 } // try to build from published parts
1027 } // process arguments
1029 set<string> anObjEntryMap;
1030 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1032 int nb = aParts->length();
1033 aResParts->length(nb);
1036 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1037 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1038 GEOM::TPythonDump pd (aFunction, true);
1041 for ( ; i < nb; i++ )
1043 const GEOM::GEOM_Object_var& anObj = aParts[ i ];
1044 if (CORBA::is_nil(anObj))
1046 char* anEntry = anObj->GetEntry();
1047 if (anObjEntryMap.count(anEntry))
1048 continue; // already treated
1049 anObjEntryMap.insert(anEntry);
1050 aResParts[nbRes++] = anObj;
1051 // clear python dump of object
1052 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1053 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1054 if ( !anObjFun.IsNull() )
1055 anObjFun->SetDescription( "" );
1061 pd <<"]" << " = geompy.RestoreSubShapes(" << aMainObj << ", " << "[";
1062 i = 0; nb = theArgs.length(); j = 0;
1063 for ( ; i < nb; i++ )
1065 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1066 if (CORBA::is_nil(anObj))
1068 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1074 pd <<"]" << ", " <<"geompy.GEOM.";
1075 switch (theFindMethod) {
1076 case GEOM::FSM_GetInPlace:
1077 pd << "FSM_GetInPlace"; break;
1078 case GEOM::FSM_Transformed:
1079 pd << "FSM_Transformed"; break;
1080 case GEOM::FSM_GetSame:
1081 pd << "FSM_GetSame"; break;
1082 case GEOM::FSM_GetShapesOnShape:
1083 pd << "FSM_GetShapesOnShape"; break;
1084 case GEOM::FSM_GetInPlaceByHistory:
1086 pd << "FSM_GetInPlaceByHistory"; break;
1088 pd << ", " << theInheritFirstArg << ")";
1090 aResParts->length(nbRes);
1091 return aResParts._retn();
1094 //============================================================================
1095 // function : RestoreSubShapesOneLevel
1096 // purpose : Private method
1097 //============================================================================
1098 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1099 SALOMEDS::SObject_ptr theOldSO,
1100 SALOMEDS::SObject_ptr theNewSO,
1101 GEOM::GEOM_Object_ptr theNewO,
1102 GEOM::find_shape_method theFindMethod)
1105 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1106 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1107 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1108 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1109 return aParts._retn();
1111 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1113 // Get interface, containing method, which we will use to reconstruct sub-shapes
1114 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1115 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1117 // Reconstruct published sub-shapes
1118 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1121 for (it->Init(); it->More(); it->Next()) {
1124 aParts->length(aLen);
1126 for (it->Init(); it->More(); it->Next()) {
1127 SALOMEDS::SObject_var anOldSubSO = it->Value();
1129 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1131 SALOMEDS::GenericAttribute_var anAttr;
1132 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1133 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1134 GEOM::GEOM_Object_var anOldSubO =
1135 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1136 if (!CORBA::is_nil(anOldSubO)) {
1137 // Find a sub-shape of theNewO in place of anOldSubO
1138 GEOM::GEOM_Object_var aNewSubO;
1139 switch (theFindMethod) {
1140 case GEOM::FSM_GetInPlace:
1143 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1146 case GEOM::FSM_Transformed:
1148 // transformation, cannot use GetInPlace, operate with indices
1149 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1150 if (anIDs->length() > 1) {
1152 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1153 if (!CORBA::is_nil(aNewSubO))
1154 aGroupOp->UnionIDs(aNewSubO, anIDs);
1158 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1162 case GEOM::FSM_GetSame:
1165 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1168 case GEOM::FSM_GetShapesOnShape:
1170 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1171 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1172 (short)GEOM::SOLID, GEOM::ST_ONIN);
1175 case GEOM::FSM_GetInPlaceByHistory:
1177 // Use GetInPlaceByHistory
1178 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1185 if (!CORBA::is_nil(aNewSubO)) {
1186 // add the part to the list
1187 aParts[i] = aNewSubO;
1189 // add to parts list
1190 addToListOfGO( aNewSubO, aNewParts );
1192 SALOMEDS::SObject_var aNewSubSO;
1193 if (!CORBA::is_nil(theNewSO)) {
1194 // Publish the sub-shape
1195 TCollection_AsciiString aSubName ("from_");
1196 aSubName += anArgName;
1197 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1198 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1200 aNewSubO->SetColor(anOldSubO->GetColor());
1202 // Restore published sub-shapes of the argument
1203 GEOM::ListOfGO_var aSubParts;
1204 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1205 // pass the main shape as Object, because only it has the history
1206 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1208 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
1209 // add to parts list
1210 addToListOfGO( aSubParts, aNewParts );
1212 else { // GetInPlace failed, try to build from published parts
1213 SALOMEDS::SObject_var aNewSubSO;
1214 if (!CORBA::is_nil(theNewSO))
1215 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1217 // Restore published sub-shapes of the argument
1218 GEOM::ListOfGO_var aSubParts =
1219 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1220 // add to parts list
1221 addToListOfGO( aSubParts, aNewParts );
1223 if (aSubParts->length() > 0) {
1224 // try to build an object from a set of its sub-shapes,
1225 // that published and will be reconstructed
1226 if (aSubParts->length() > 1) {
1227 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1228 // add to parts list
1229 addToListOfGO( aNewSubO, aNewParts );
1232 aNewSubO = aSubParts[0];
1235 if (!CORBA::is_nil(aNewSubO)) {
1236 // add the part to the list
1237 aSubParts[i] = aNewSubO;
1240 // Publish the sub-shape
1241 if (!CORBA::is_nil(aNewSubSO)) {
1242 TCollection_AsciiString aSubName = "from_parts_of_";
1243 aSubName += anArgName;
1244 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1246 aNewSubO->SetColor(anOldSubO->GetColor());
1250 else if (!CORBA::is_nil(aNewSubSO)) {
1251 // remove created aSubSO, because no parts have been found
1252 aStudyBuilder->RemoveObject(aNewSubSO);
1254 } // try to build from published parts
1257 } // iterate on published sub-shapes
1260 // add to parts list
1261 addToListOfGO( aNewParts, aParts );
1262 return aParts._retn();
1265 //============================================================================
1266 // function : register()
1267 // purpose : register 'name' in 'name_service'
1268 //============================================================================
1269 void GEOM_Gen_i::register_name(char * name)
1271 GEOM::GEOM_Gen_var g = _this();
1272 name_service->Register(g, name);
1275 //============================================================================
1278 //============================================================================
1279 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
1281 _impl->Undo(theStudyID);
1284 //============================================================================
1287 //============================================================================
1288 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
1290 _impl->Redo(theStudyID);
1293 //============================================================================
1294 // function : GetIBasicOperations
1296 //============================================================================
1297 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1298 throw ( SALOME::SALOME_Exception )
1300 Unexpect aCatch(SALOME_SalomeException);
1301 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1303 GEOM::GEOM_Gen_ptr engine = _this();
1305 //transfer reference on engine
1306 GEOM_IBasicOperations_i* aServant =
1307 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1309 // activate the CORBA servant
1310 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1311 return operations._retn();
1314 //============================================================================
1315 // function : GetITransformOperations
1317 //============================================================================
1318 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1319 throw ( SALOME::SALOME_Exception )
1321 Unexpect aCatch(SALOME_SalomeException);
1322 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1324 GEOM::GEOM_Gen_ptr engine = _this();
1326 GEOM_ITransformOperations_i* aServant =
1327 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1329 // activate the CORBA servant
1330 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1331 return operations._retn();
1334 //============================================================================
1335 // function : GetI3DPrimOperations
1337 //============================================================================
1338 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1339 throw ( SALOME::SALOME_Exception )
1341 Unexpect aCatch(SALOME_SalomeException);
1342 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1344 GEOM::GEOM_Gen_ptr engine = _this();
1346 GEOM_I3DPrimOperations_i* aServant =
1347 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1349 // activate the CORBA servant
1350 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1351 return operations._retn();
1354 //============================================================================
1355 // function : GetIShapesOperations
1357 //============================================================================
1358 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1359 throw ( SALOME::SALOME_Exception )
1361 Unexpect aCatch(SALOME_SalomeException);
1362 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1364 GEOM::GEOM_Gen_ptr engine = _this();
1366 GEOM_IShapesOperations_i* aServant =
1367 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1369 // activate the CORBA servant
1370 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1371 return operations._retn();
1374 //============================================================================
1375 // function : GetIBlocksOperations
1377 //============================================================================
1378 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1379 throw ( SALOME::SALOME_Exception )
1381 Unexpect aCatch(SALOME_SalomeException);
1382 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1384 GEOM::GEOM_Gen_ptr engine = _this();
1386 GEOM_IBlocksOperations_i* aServant =
1387 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1389 // activate the CORBA servant
1390 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1391 return operations._retn();
1394 //============================================================================
1395 // function : GetIBooleanOperations
1397 //============================================================================
1398 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1399 throw ( SALOME::SALOME_Exception )
1401 Unexpect aCatch(SALOME_SalomeException);
1402 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1404 GEOM::GEOM_Gen_ptr engine = _this();
1406 GEOM_IBooleanOperations_i* aServant =
1407 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1409 // activate the CORBA servant
1410 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1411 return operations._retn();
1414 //============================================================================
1415 // function : GetICurvesOperations
1417 //============================================================================
1418 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1419 throw ( SALOME::SALOME_Exception )
1421 Unexpect aCatch(SALOME_SalomeException);
1422 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1424 GEOM::GEOM_Gen_ptr engine = _this();
1426 GEOM_ICurvesOperations_i* aServant =
1427 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1429 // activate the CORBA servant
1430 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1431 return operations._retn();
1434 //============================================================================
1435 // function : GetILocalOperations
1437 //============================================================================
1438 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1439 throw ( SALOME::SALOME_Exception )
1441 Unexpect aCatch(SALOME_SalomeException);
1442 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1444 GEOM::GEOM_Gen_ptr engine = _this();
1446 GEOM_ILocalOperations_i* aServant =
1447 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1449 // activate the CORBA servant
1450 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1451 return operations._retn();
1454 //============================================================================
1455 // function : GetIHealingOperations
1457 //============================================================================
1458 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1459 throw ( SALOME::SALOME_Exception )
1461 Unexpect aCatch(SALOME_SalomeException);
1462 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1464 GEOM::GEOM_Gen_ptr engine = _this();
1466 GEOM_IHealingOperations_i* aServant =
1467 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1469 // activate the CORBA servant
1470 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1471 return operations._retn();
1474 //============================================================================
1475 // function : GetIInsertOperations
1477 //============================================================================
1478 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1479 throw ( SALOME::SALOME_Exception )
1481 Unexpect aCatch(SALOME_SalomeException);
1482 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1484 GEOM::GEOM_Gen_ptr engine = _this();
1486 GEOM_IInsertOperations_i* aServant =
1487 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1489 // activate the CORBA servant
1490 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1491 return operations._retn();
1494 //============================================================================
1495 // function : GetIMeasureOperations
1497 //============================================================================
1498 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1499 throw ( SALOME::SALOME_Exception )
1501 Unexpect aCatch(SALOME_SalomeException);
1502 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1504 GEOM::GEOM_Gen_ptr engine = _this();
1506 GEOM_IMeasureOperations_i* aServant =
1507 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1509 // activate the CORBA servant
1510 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1511 return operations._retn();
1514 //============================================================================
1515 // function : GetIGroupOperations
1517 //============================================================================
1518 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1519 throw ( SALOME::SALOME_Exception )
1521 Unexpect aCatch(SALOME_SalomeException);
1522 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1524 GEOM::GEOM_Gen_ptr engine = _this();
1526 GEOM_IGroupOperations_i* aServant =
1527 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1529 // activate the CORBA servant
1530 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1531 return operations._retn();
1534 //=============================================================================
1538 //=============================================================================
1539 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1540 const GEOM::ListOfLong& theIndices)
1542 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1543 return GEOM::GEOM_Object::_nil();
1544 CORBA::String_var entry = theMainShape->GetEntry();
1545 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1546 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1548 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1549 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1551 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1552 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1554 TCollection_AsciiString anEntry;
1555 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1556 return GetObject(anObject->GetDocID(), anEntry.ToCString());
1559 //=============================================================================
1563 //=============================================================================
1564 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1566 CORBA::String_var anEntry = theObject->GetEntry();
1567 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1568 if (anObject.IsNull()) return;
1569 _impl->RemoveObject(anObject);
1574 //=================================================================================
1575 // function : GetStringFromIOR()
1576 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
1577 //=================================================================================
1578 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1579 return _orb->object_to_string(theObject);
1583 //=================================================================================
1584 // function : GetIORFromString()
1585 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
1586 //=================================================================================
1587 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1588 GEOM::GEOM_Object_var aGeomObject;
1589 if(strcmp(stringIOR,"") != 0){
1590 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1591 if(!CORBA::is_nil(anObject))
1592 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
1594 return aGeomObject._retn();
1597 //=================================================================================
1598 // function : GetObject()
1600 //=================================================================================
1601 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1603 GEOM::GEOM_Object_var obj;
1604 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1605 if (handle_object.IsNull()) return obj._retn();
1607 TCollection_AsciiString stringIOR = handle_object->GetIOR();
1608 if (stringIOR.Length() > 1) {
1609 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1610 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1614 GEOM::GEOM_Gen_ptr engine = _this();
1615 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1617 obj = servant->_this();
1618 CORBA::String_var objStr = _orb->object_to_string(obj);
1619 TCollection_AsciiString anAscii( (char *)objStr.in() );
1620 handle_object->SetIOR( anAscii );
1624 //=================================================================================
1625 // function : hasObjectInfo()
1626 // purpose : shows if module provides information for its objects
1627 //=================================================================================
1628 bool GEOM_Gen_i::hasObjectInfo()
1633 //=================================================================================
1634 // function : getObjectInfo()
1635 // purpose : returns an information for a given object by its entry
1636 //=================================================================================
1637 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1639 GEOM::GEOM_Object_var aGeomObject;
1641 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1642 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1643 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1644 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1645 SALOMEDS::SObject_var aResultSObj;
1646 if (aSObj->ReferencedObject(aResultSObj))
1647 aSObj = aResultSObj;
1649 SALOMEDS::GenericAttribute_var anAttr;
1650 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1651 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1652 CORBA::String_var aVal = anIOR->Value();
1653 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1654 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1657 const char* aTypeInfo = "Object";
1658 if ( !aGeomObject->_is_nil() ) {
1659 GEOM::GEOM_IKindOfShape::shape_kind aKind;
1660 GEOM::ListOfLong_var anInts;
1661 GEOM::ListOfDouble_var aDbls;
1663 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1664 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1666 if ( anOp->IsDone() ) {
1668 case GEOM::GEOM_IKindOfShape::COMPOUND:
1669 aTypeInfo = "Compound";
1671 case GEOM::GEOM_IKindOfShape::COMPSOLID:
1672 aTypeInfo = "CompSolid";
1674 case GEOM::GEOM_IKindOfShape::SHELL:
1675 aTypeInfo = "Shell";
1677 case GEOM::GEOM_IKindOfShape::WIRE:
1678 if ( anInts[0] == 1 )
1679 aTypeInfo = "Closed Wire";
1680 else if ( anInts[0] == 2 )
1681 aTypeInfo = "Opened Wire";
1686 case GEOM::GEOM_IKindOfShape::SPHERE:
1687 aTypeInfo = "Sphere";
1689 case GEOM::GEOM_IKindOfShape::CYLINDER:
1690 aTypeInfo = "Cylinder";
1692 case GEOM::GEOM_IKindOfShape::BOX:
1693 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1696 case GEOM::GEOM_IKindOfShape::TORUS:
1697 aTypeInfo = "Torus";
1699 case GEOM::GEOM_IKindOfShape::CONE:
1702 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1703 aTypeInfo = "Polyhedron";
1705 case GEOM::GEOM_IKindOfShape::SOLID:
1706 aTypeInfo = "Solid";
1709 case GEOM::GEOM_IKindOfShape::SPHERE2D:
1710 aTypeInfo = "Spherical Face";
1712 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1713 aTypeInfo = "Cylindrical Face";
1715 case GEOM::GEOM_IKindOfShape::TORUS2D:
1716 aTypeInfo = "Toroidal Face";
1718 case GEOM::GEOM_IKindOfShape::CONE2D:
1719 aTypeInfo = "Conical Face";
1721 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1724 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1725 aTypeInfo = "Elliptical Face";
1727 case GEOM::GEOM_IKindOfShape::POLYGON:
1728 aTypeInfo = "Polygon";
1730 case GEOM::GEOM_IKindOfShape::PLANE:
1731 aTypeInfo = "Plane";
1733 case GEOM::GEOM_IKindOfShape::PLANAR:
1734 aTypeInfo = "Planar Face";
1736 case GEOM::GEOM_IKindOfShape::FACE:
1740 case GEOM::GEOM_IKindOfShape::CIRCLE:
1741 aTypeInfo = "Circle";
1743 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1746 case GEOM::GEOM_IKindOfShape::ELLIPSE:
1747 aTypeInfo = "Ellipse";
1749 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1750 aTypeInfo = "Arc Ellipse";
1752 case GEOM::GEOM_IKindOfShape::LINE:
1755 case GEOM::GEOM_IKindOfShape::SEGMENT:
1756 aTypeInfo = "Segment";
1758 case GEOM::GEOM_IKindOfShape::EDGE:
1761 case GEOM::GEOM_IKindOfShape::VERTEX:
1762 aTypeInfo = "Vertex";
1770 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1771 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1773 char* ret = CORBA::string_dup(anInfo);
1778 //=====================================================================================
1780 //=====================================================================================
1784 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1785 PortableServer::POA_ptr poa,
1786 PortableServer::ObjectId * contId,
1787 const char *instanceName,
1788 const char * interfaceName)
1790 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1791 // Don't understand the reason of this register ????
1792 // myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1793 return myGEOM_Gen_i->getId();