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());
365 CORBA::String_var GrEntry = GrObj->GetEntry();
366 Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
368 //Handle(GEOM_Object) anObj;
369 for(int i=1; i<=SeqS.Length(); i++) {
370 TopoDS_Shape aValue = SeqS.Value(i);
371 //anArray = new TColStd_HArray1OfInteger(1,1);
372 Standard_Integer anIndex = anIndices.FindIndex(aValue);
373 //anArray->SetValue(1, anIndex);
374 GOp->AddObject(GrObj,anIndex);
375 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
376 //if (anObj.IsNull()) continue;
377 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
378 //if (aFunction.IsNull()) continue;
379 //GEOM_ISubShape aSSI(aFunction);
380 //aSSI.SetMainShape(aMainShape->GetLastFunction());
381 //aSSI.SetIndices(anArray);
382 //aFunction->SetValue(aValue);
383 //GOp->UnionIDs(GrObj, anIndex);
384 //SALOMEDS::SObject_var aResultSO;
385 //TCollection_AsciiString anEntry;
386 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
387 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
388 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
394 //============================================================================
395 // function : PublishNamedShapesInStudy
397 //============================================================================
398 GEOM::ListOfGO* GEOM_Gen_i::
399 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
400 //SALOMEDS::SObject_ptr theSObject,
401 CORBA::Object_ptr theObject)
403 //Unexpect aCatch(SALOME_SalomeException);
404 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
406 //CORBA::Object_var theObject = theSObject->GetObject();
407 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
408 if(theMainShape->_is_nil()) return aResList._retn();
410 CORBA::String_var entry = theMainShape->GetEntry();
411 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
412 if (aMainShape.IsNull()) return aResList._retn();
413 TopoDS_Shape MainSh = aMainShape->GetValue();
415 TDF_Label aMainLbl = aMainShape->GetEntry();
416 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
417 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
418 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
419 for(; anIt.More(); anIt.Next()) {
420 Handle(TNaming_NamedShape) anAttr =
421 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
422 if(anAttr.IsNull()) continue;
423 TopoDS_Shape S = anAttr->Get();
424 TDF_Label L = anAttr->Label();
425 //if(S.IsEqual(MainSh)) continue;
426 Handle(TDataStd_Name) aName;
427 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
428 TCollection_ExtendedString EName = aName->Get();
429 if(S.ShapeType()==TopAbs_SOLID) {
431 SolidSeqN.Append(aName->Get());
433 else if(S.ShapeType()==TopAbs_FACE) {
435 FaceSeqN.Append(aName->Get());
437 else if(S.ShapeType()==TopAbs_EDGE) {
439 EdgeSeqN.Append(aName->Get());
441 else if(S.ShapeType()==TopAbs_VERTEX) {
443 VertSeqN.Append(aName->Get());
448 TopTools_IndexedMapOfShape anIndices;
449 TopExp::MapShapes(MainSh, anIndices);
451 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
452 "Group_Of_Named_Solids", aResList);
454 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
455 "Group_Of_Named_Faces", aResList);
457 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
458 "Group_Of_Named_Edges", aResList);
460 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
461 "Group_Of_Named_Vertices", aResList);
463 return aResList._retn();
467 //============================================================================
469 // purpose : save OCAF/Geom document
470 //============================================================================
471 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
474 SALOMEDS::TMPFile_var aStreamFile;
475 // Get a temporary directory to store a file
476 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
478 // OCCT BUG: cannot save a document (in current folder)
479 // if directory name is empty
480 if (aTmpDir.size() == 0) {
488 // Create a list to store names of created files
489 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
491 // Prepare a file name to open
492 TCollection_AsciiString aNameWithExt("");
494 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
495 (theComponent->GetStudy()->URL())).c_str());
496 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
497 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
498 // Build a full file name of temporary file
499 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
500 // Save GEOM component in this file
501 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
502 // Conver a file to the byte stream
503 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
504 // Remove the created file and tmp directory
505 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
507 // Return the created byte stream
508 return aStreamFile._retn();
512 //============================================================================
513 // function : SaveASCII()
515 //============================================================================
516 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
519 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
520 return aStreamFile._retn();
524 //============================================================================
527 //============================================================================
528 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
529 const SALOMEDS::TMPFile& theStream,
533 if (theStream.length() <= 9) {
534 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
538 // Get a temporary directory for a file
539 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
541 // OCCT BUG: cannot load a document (from current folder)
542 // if directory name is empty
543 if (aTmpDir.size() == 0) {
551 // Conver the byte stream theStream to a file and place it in tmp directory
552 SALOMEDS::ListOfFileNames_var aSeq =
553 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
555 // Prepare a file name to open
556 TCollection_AsciiString aNameWithExt("");
558 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
559 (theComponent->GetStudy()->URL())).c_str());
560 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
561 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
564 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
566 // Remove the created file and tmp directory
567 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
569 SALOMEDS::Study_var Study = theComponent->GetStudy();
570 TCollection_AsciiString name (Study->Name());
576 //============================================================================
577 // function : LoadASCII()
579 //============================================================================
580 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
581 const SALOMEDS::TMPFile& theStream,
584 return Load(theComponent, theStream, theURL, isMultiFile);
588 //============================================================================
589 // function : Close()
591 //============================================================================
592 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
594 _impl->Close(theComponent->GetStudy()->StudyId());
597 //============================================================================
598 // function : CanCopy()
600 //============================================================================
601 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
602 // Try to retrieve known by Geometry component GEOM_Object by given IOR
603 SALOMEDS::GenericAttribute_var anAttr;
604 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
606 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
608 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
609 // If the object is null one it can't be copied: return false
610 if (anObject->_is_nil()) return false;
614 //============================================================================
615 // function : CopyFrom()
617 //============================================================================
618 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
620 // Declare a sequence of the byte to store the copied object
621 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
623 // Try to get GEOM_Object object by given SObject
624 SALOMEDS::GenericAttribute_var anAttr;
625 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
626 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
627 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
628 if (anObject->_is_nil()) return aStreamFile._retn();
630 aStreamFile = anObject->GetShapeStream();
632 // Assign an ID the type of GEOM_Object
633 theObjectID = anObject->GetType();
635 // Return created TMPFile
636 return aStreamFile._retn();
639 //============================================================================
640 // function : CanPaste()
642 //============================================================================
643 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
644 // The Geometry component can paste only objects copied by Geometry component
645 // and with the object type = 1
646 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
650 //============================================================================
651 // function : PasteInto()
653 //============================================================================
654 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
655 CORBA::Long theObjectID,
656 SALOMEDS::SObject_ptr theObject) {
657 // Find the current Study and StudyBuilder
658 SALOMEDS::Study_var aStudy = theObject->GetStudy();
659 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
661 // Retrieve a TopoDS_Shape from byte stream
662 TopoDS_Shape aTopology;
663 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
664 BRep_Builder aBuilder;
666 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
667 } catch (Standard_Failure) {
671 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
672 SALOMEDS::SObject_var aNewSO;
673 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
674 aNewSO = aStudyBuilder->NewObject(theObject);
675 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
678 //Create a new GEOM_Object
679 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
680 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
681 aFunction->SetValue(aTopology);
683 TCollection_AsciiString anEntry;
684 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
685 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
687 //Set the study entry of the published GEOM_Object
688 obj->SetStudyEntry(aNewSO->GetID());
690 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
691 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
692 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
693 CORBA::String_var objStr = _orb->object_to_string(obj);
694 anIOR->SetValue(objStr.in());
696 // Return the created in the Study SObject
697 return aNewSO._retn();
700 //============================================================================
701 // function : ComponentDataType()
703 //============================================================================
704 char* GEOM_Gen_i::ComponentDataType()
706 return CORBA::string_dup("GEOM");
709 //============================================================================
710 // function : AddInStudy
712 //============================================================================
713 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
714 GEOM::GEOM_Object_ptr theObject,
716 GEOM::GEOM_Object_ptr theFather)
718 SALOMEDS::SObject_var aResultSO;
719 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
721 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
722 CORBA::String_var IOR;
724 if(!theFather->_is_nil()) {
725 IOR = _orb->object_to_string(theFather);
726 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
727 if(aFatherSO->_is_nil()) return aResultSO._retn();
728 aResultSO = aStudyBuilder->NewObject(aFatherSO);
729 //aStudyBuilder->Addreference(aResultSO, aResultSO);
732 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
733 if(aResultSO->_is_nil()) return aResultSO._retn();
735 GEOM::ListOfGO_var aList = theObject->GetDependency();
736 Standard_Integer aLength = aList->length();
737 if(aLength < 1) return aResultSO._retn();
739 //Publish the arguments
740 for(Standard_Integer i = 0; i< aLength; i++) {
741 GEOM::GEOM_Object_var anObject = aList[i];
742 if(anObject->_is_nil()) continue;
743 IOR = _orb->object_to_string(anObject);
744 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
745 if(aSO->_is_nil()) continue;
746 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
747 aStudyBuilder->Addreference(aSubSO, aSO);
750 return aResultSO._retn();
753 //============================================================================
754 // function : RestoreSubShapesO
755 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
756 // To be used from python scripts out of geompy.addToStudy (non-default usage)
757 //============================================================================
758 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
759 GEOM::GEOM_Object_ptr theObject,
760 const GEOM::ListOfGO& theArgs,
761 GEOM::find_shape_method theFindMethod,
762 CORBA::Boolean theInheritFirstArg)
764 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
765 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
766 return aParts._retn();
768 // find SObject in the study if it is already published
769 CORBA::String_var anIORo = _orb->object_to_string(theObject);
770 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
771 //PTv, IMP 0020001, The salome object <aSO>
772 // is not obligatory in case of invokation from script
773 // if (CORBA::is_nil(aSO))
774 // return aParts._retn();
776 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
777 return aParts._retn();
780 //============================================================================
781 // function : RestoreSubShapesSO
782 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
783 // To be used from GUI and from geompy.addToStudy
784 //============================================================================
785 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
786 SALOMEDS::SObject_ptr theSObject,
787 const GEOM::ListOfGO& theArgs,
788 GEOM::find_shape_method theFindMethod,
789 CORBA::Boolean theInheritFirstArg)
791 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
792 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
793 return aParts._retn();
795 SALOMEDS::GenericAttribute_var anAttr;
796 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
797 return aParts._retn();
799 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
800 CORBA::String_var anIORso = anAttrIOR->Value();
802 // get Object from SObject
803 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
804 if (CORBA::is_nil(anO))
805 return aParts._retn();
807 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
808 return aParts._retn();
811 //============================================================================
812 // function : addToListOfGO
813 // purpose : static local function
814 //============================================================================
815 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
816 GEOM::ListOfGO& theList )
818 const int oldLen = theList.length();
819 theList.length(oldLen + 1);
820 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
823 //============================================================================
824 // function : addToListOfGO
825 // purpose : static local function
826 //============================================================================
827 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
828 GEOM::ListOfGO& theTrgList )
830 const int oldLen = theTrgList.length();
831 const int srcLen = theSrcList.length();
832 theTrgList.length(oldLen + srcLen);
833 for( int i = 0; i < srcLen; i++ )
834 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
837 //============================================================================
838 // function : RestoreSubShapes
839 // purpose : Private method. Works only if both theObject and theSObject
840 // are defined, and does not check, if they correspond to each other.
841 //============================================================================
842 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
843 GEOM::GEOM_Object_ptr theObject,
844 SALOMEDS::SObject_ptr theSObject,
845 const GEOM::ListOfGO& theArgs,
846 GEOM::find_shape_method theFindMethod,
847 CORBA::Boolean theInheritFirstArg)
849 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
850 //PTv, IMP 0020001, The salome object <theSObject>
851 // is not obligatory in case of invokation from script
852 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
853 return aParts._retn();
855 // Arguments to be published
856 GEOM::ListOfGO_var aList;
858 // If theArgs list is empty, we try to publish all arguments,
859 // otherwise publish only passed args
860 Standard_Integer nbArgsActual = -1; // -1 means unknown
861 Standard_Integer aLength = theArgs.length();
863 aList = new GEOM::ListOfGO;
864 aList->length(aLength);
865 for (int i = 0; i < aLength; i++) {
866 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
871 aList = theObject->GetDependency();
872 aLength = aList->length();
873 nbArgsActual = aLength;
877 return aParts._retn();
879 if (theInheritFirstArg || (nbArgsActual == 1)) {
880 // Do not publish argument's reflection,
881 // but only reconstruct its published sub-shapes
883 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
884 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
886 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
888 // set the color of the transformed shape to the color of initial shape
889 theObject->SetColor(aList[0]->GetColor());
892 // Get interface, containing method, which we will use to reconstruct sub-shapes
893 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
894 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
896 // Reconstruct arguments and tree of sub-shapes of the arguments
897 CORBA::String_var anIOR;
898 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
899 for (Standard_Integer i = 0; i < aLength; i++)
901 GEOM::GEOM_Object_var anArgO = aList[i];
902 if (!CORBA::is_nil(anArgO)) {
903 anIOR = _orb->object_to_string(anArgO);
904 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
905 TCollection_AsciiString anArgName;
906 if (CORBA::is_nil(anArgSO)) {
908 anArgName += TCollection_AsciiString(i);
911 anArgName = anArgSO->GetName();
914 // Find a sub-shape of theObject in place of the argument
915 GEOM::GEOM_Object_var aSubO;
916 switch (theFindMethod) {
917 case GEOM::FSM_GetInPlace:
920 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
923 case GEOM::FSM_Transformed:
925 // transformation, cannot use GetInPlace, operate with indices
926 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
927 if (anIDs->length() > 1) {
929 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
930 if (!CORBA::is_nil(aSubO))
931 aGroupOp->UnionIDs(aSubO, anIDs);
933 else if (anIDs->length() > 0) {
935 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
939 case GEOM::FSM_GetSame:
942 aSubO = aShapesOp->GetSame(theObject, anArgO);
945 case GEOM::FSM_GetShapesOnShape:
947 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
948 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
949 (short)GEOM::SOLID, GEOM::ST_ONIN);
952 case GEOM::FSM_GetInPlaceByHistory:
954 // Use GetInPlaceByHistory
955 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
962 if (!CORBA::is_nil(aSubO)) {
964 addToListOfGO( aSubO, aParts );
966 // Publish the sub-shape
967 SALOMEDS::SObject_var aSubSO;
968 if (!CORBA::is_nil(theSObject)) {
969 TCollection_AsciiString aSubName ("from_");
970 aSubName += anArgName;
971 aSubSO = aStudyBuilder->NewObject(theSObject);
972 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
974 aSubO->SetColor(anArgO->GetColor());
977 if (!CORBA::is_nil(anArgSO)) {
978 // Restore published sub-shapes of the argument
979 GEOM::ListOfGO_var aSubParts;
980 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
981 // pass theObject, because only it has the history
982 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
984 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
986 addToListOfGO( aSubParts, aParts );
989 else { // GetInPlace failed, try to build from published parts
990 if (!CORBA::is_nil(anArgSO)) {
991 SALOMEDS::SObject_var aSubSO;
992 if (!CORBA::is_nil(theSObject))
993 aSubSO = aStudyBuilder->NewObject(theSObject);
995 // Restore published sub-shapes of the argument
996 GEOM::ListOfGO_var aSubParts =
997 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
1000 addToListOfGO( aSubParts, aParts );
1002 if (aSubParts->length() > 0) {
1003 // try to build an argument from a set of its sub-shapes,
1004 // that published and will be reconstructed
1005 if (aSubParts->length() > 1) {
1006 aSubO = aShapesOp->MakeCompound(aSubParts);
1007 // add to parts list
1008 addToListOfGO( aSubO, aParts );
1011 aSubO = aSubParts[0];
1013 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1014 // Publish the sub-shape
1015 TCollection_AsciiString aSubName ("from_parts_of_");
1016 aSubName += anArgName;
1017 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1019 aSubO->SetColor(anArgO->GetColor());
1022 else if (!CORBA::is_nil(aSubSO)) {
1023 // remove created aSubSO, because no parts have been found
1024 aStudyBuilder->RemoveObject(aSubSO);
1027 } // try to build from published parts
1029 } // process arguments
1031 set<string> anObjEntryMap;
1032 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1034 int nb = aParts->length();
1035 aResParts->length(nb);
1038 Handle(GEOM_Object) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1039 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1040 GEOM::TPythonDump pd (aFunction, true);
1043 for ( ; i < nb; i++ )
1045 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1046 if (CORBA::is_nil(anObj))
1048 char* anEntry = anObj->GetEntry();
1049 if (anObjEntryMap.count(anEntry))
1050 continue; // already treated
1051 anObjEntryMap.insert(anEntry);
1052 aResParts[nbRes++] = anObj;
1053 // clear python dump of object
1054 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1055 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1056 if ( !anObjFun.IsNull() )
1057 anObjFun->SetDescription( "" );
1063 pd <<"]" << " = geompy.RestoreSubShapes(" << aMainObj << ", " << "[";
1064 i = 0; nb = theArgs.length(); j = 0;
1065 for ( ; i < nb; i++ )
1067 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1068 if (CORBA::is_nil(anObj))
1070 Handle(GEOM_Object) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1076 pd <<"]" << ", " <<"geompy.GEOM.";
1077 switch (theFindMethod) {
1078 case GEOM::FSM_GetInPlace:
1079 pd << "FSM_GetInPlace"; break;
1080 case GEOM::FSM_Transformed:
1081 pd << "FSM_Transformed"; break;
1082 case GEOM::FSM_GetSame:
1083 pd << "FSM_GetSame"; break;
1084 case GEOM::FSM_GetShapesOnShape:
1085 pd << "FSM_GetShapesOnShape"; break;
1086 case GEOM::FSM_GetInPlaceByHistory:
1088 pd << "FSM_GetInPlaceByHistory"; break;
1090 pd << ", " << theInheritFirstArg << ")";
1092 aResParts->length(nbRes);
1093 return aResParts._retn();
1096 //============================================================================
1097 // function : RestoreSubShapesOneLevel
1098 // purpose : Private method
1099 //============================================================================
1100 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1101 SALOMEDS::SObject_ptr theOldSO,
1102 SALOMEDS::SObject_ptr theNewSO,
1103 GEOM::GEOM_Object_ptr theNewO,
1104 GEOM::find_shape_method theFindMethod)
1107 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1108 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1109 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1110 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1111 return aParts._retn();
1113 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1115 // Get interface, containing method, which we will use to reconstruct sub-shapes
1116 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1117 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1119 // Reconstruct published sub-shapes
1120 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1123 for (it->Init(); it->More(); it->Next()) {
1126 aParts->length(aLen);
1128 for (it->Init(); it->More(); it->Next()) {
1129 SALOMEDS::SObject_var anOldSubSO = it->Value();
1131 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1133 SALOMEDS::GenericAttribute_var anAttr;
1134 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1135 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1136 GEOM::GEOM_Object_var anOldSubO =
1137 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1138 if (!CORBA::is_nil(anOldSubO)) {
1139 // Find a sub-shape of theNewO in place of anOldSubO
1140 GEOM::GEOM_Object_var aNewSubO;
1141 switch (theFindMethod) {
1142 case GEOM::FSM_GetInPlace:
1145 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1148 case GEOM::FSM_Transformed:
1150 // transformation, cannot use GetInPlace, operate with indices
1151 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1152 if (anIDs->length() > 1) {
1154 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1155 if (!CORBA::is_nil(aNewSubO))
1156 aGroupOp->UnionIDs(aNewSubO, anIDs);
1160 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1164 case GEOM::FSM_GetSame:
1167 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1170 case GEOM::FSM_GetShapesOnShape:
1172 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1173 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1174 (short)GEOM::SOLID, GEOM::ST_ONIN);
1177 case GEOM::FSM_GetInPlaceByHistory:
1179 // Use GetInPlaceByHistory
1180 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1187 if (!CORBA::is_nil(aNewSubO)) {
1188 // add the part to the list
1189 aParts[i] = aNewSubO;
1191 // add to parts list
1192 addToListOfGO( aNewSubO, aNewParts );
1194 SALOMEDS::SObject_var aNewSubSO;
1195 if (!CORBA::is_nil(theNewSO)) {
1196 // Publish the sub-shape
1197 TCollection_AsciiString aSubName ("from_");
1198 aSubName += anArgName;
1199 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1200 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1202 aNewSubO->SetColor(anOldSubO->GetColor());
1204 // Restore published sub-shapes of the argument
1205 GEOM::ListOfGO_var aSubParts;
1206 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1207 // pass the main shape as Object, because only it has the history
1208 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1210 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
1211 // add to parts list
1212 addToListOfGO( aSubParts, aNewParts );
1214 else { // GetInPlace failed, try to build from published parts
1215 SALOMEDS::SObject_var aNewSubSO;
1216 if (!CORBA::is_nil(theNewSO))
1217 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1219 // Restore published sub-shapes of the argument
1220 GEOM::ListOfGO_var aSubParts =
1221 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1222 // add to parts list
1223 addToListOfGO( aSubParts, aNewParts );
1225 if (aSubParts->length() > 0) {
1226 // try to build an object from a set of its sub-shapes,
1227 // that published and will be reconstructed
1228 if (aSubParts->length() > 1) {
1229 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1230 // add to parts list
1231 addToListOfGO( aNewSubO, aNewParts );
1234 aNewSubO = aSubParts[0];
1237 if (!CORBA::is_nil(aNewSubO)) {
1238 // add the part to the list
1239 aSubParts[i] = aNewSubO;
1242 // Publish the sub-shape
1243 if (!CORBA::is_nil(aNewSubSO)) {
1244 TCollection_AsciiString aSubName = "from_parts_of_";
1245 aSubName += anArgName;
1246 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1248 aNewSubO->SetColor(anOldSubO->GetColor());
1252 else if (!CORBA::is_nil(aNewSubSO)) {
1253 // remove created aSubSO, because no parts have been found
1254 aStudyBuilder->RemoveObject(aNewSubSO);
1256 } // try to build from published parts
1259 } // iterate on published sub-shapes
1262 // add to parts list
1263 addToListOfGO( aNewParts, aParts );
1264 return aParts._retn();
1267 //============================================================================
1268 // function : register()
1269 // purpose : register 'name' in 'name_service'
1270 //============================================================================
1271 void GEOM_Gen_i::register_name(char * name)
1273 GEOM::GEOM_Gen_var g = _this();
1274 name_service->Register(g, name);
1277 //============================================================================
1280 //============================================================================
1281 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
1283 _impl->Undo(theStudyID);
1286 //============================================================================
1289 //============================================================================
1290 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
1292 _impl->Redo(theStudyID);
1295 //============================================================================
1296 // function : GetIBasicOperations
1298 //============================================================================
1299 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1300 throw ( SALOME::SALOME_Exception )
1302 Unexpect aCatch(SALOME_SalomeException);
1303 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1305 GEOM::GEOM_Gen_ptr engine = _this();
1307 //transfer reference on engine
1308 GEOM_IBasicOperations_i* aServant =
1309 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1311 // activate the CORBA servant
1312 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1313 return operations._retn();
1316 //============================================================================
1317 // function : GetITransformOperations
1319 //============================================================================
1320 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1321 throw ( SALOME::SALOME_Exception )
1323 Unexpect aCatch(SALOME_SalomeException);
1324 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1326 GEOM::GEOM_Gen_ptr engine = _this();
1328 GEOM_ITransformOperations_i* aServant =
1329 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1331 // activate the CORBA servant
1332 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1333 return operations._retn();
1336 //============================================================================
1337 // function : GetI3DPrimOperations
1339 //============================================================================
1340 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1341 throw ( SALOME::SALOME_Exception )
1343 Unexpect aCatch(SALOME_SalomeException);
1344 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1346 GEOM::GEOM_Gen_ptr engine = _this();
1348 GEOM_I3DPrimOperations_i* aServant =
1349 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1351 // activate the CORBA servant
1352 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1353 return operations._retn();
1356 //============================================================================
1357 // function : GetIShapesOperations
1359 //============================================================================
1360 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1361 throw ( SALOME::SALOME_Exception )
1363 Unexpect aCatch(SALOME_SalomeException);
1364 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1366 GEOM::GEOM_Gen_ptr engine = _this();
1368 GEOM_IShapesOperations_i* aServant =
1369 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1371 // activate the CORBA servant
1372 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1373 return operations._retn();
1376 //============================================================================
1377 // function : GetIBlocksOperations
1379 //============================================================================
1380 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1381 throw ( SALOME::SALOME_Exception )
1383 Unexpect aCatch(SALOME_SalomeException);
1384 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1386 GEOM::GEOM_Gen_ptr engine = _this();
1388 GEOM_IBlocksOperations_i* aServant =
1389 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1391 // activate the CORBA servant
1392 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1393 return operations._retn();
1396 //============================================================================
1397 // function : GetIBooleanOperations
1399 //============================================================================
1400 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1401 throw ( SALOME::SALOME_Exception )
1403 Unexpect aCatch(SALOME_SalomeException);
1404 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1406 GEOM::GEOM_Gen_ptr engine = _this();
1408 GEOM_IBooleanOperations_i* aServant =
1409 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1411 // activate the CORBA servant
1412 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1413 return operations._retn();
1416 //============================================================================
1417 // function : GetICurvesOperations
1419 //============================================================================
1420 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1421 throw ( SALOME::SALOME_Exception )
1423 Unexpect aCatch(SALOME_SalomeException);
1424 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1426 GEOM::GEOM_Gen_ptr engine = _this();
1428 GEOM_ICurvesOperations_i* aServant =
1429 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1431 // activate the CORBA servant
1432 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1433 return operations._retn();
1436 //============================================================================
1437 // function : GetILocalOperations
1439 //============================================================================
1440 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1441 throw ( SALOME::SALOME_Exception )
1443 Unexpect aCatch(SALOME_SalomeException);
1444 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1446 GEOM::GEOM_Gen_ptr engine = _this();
1448 GEOM_ILocalOperations_i* aServant =
1449 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1451 // activate the CORBA servant
1452 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1453 return operations._retn();
1456 //============================================================================
1457 // function : GetIHealingOperations
1459 //============================================================================
1460 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1461 throw ( SALOME::SALOME_Exception )
1463 Unexpect aCatch(SALOME_SalomeException);
1464 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1466 GEOM::GEOM_Gen_ptr engine = _this();
1468 GEOM_IHealingOperations_i* aServant =
1469 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1471 // activate the CORBA servant
1472 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1473 return operations._retn();
1476 //============================================================================
1477 // function : GetIInsertOperations
1479 //============================================================================
1480 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1481 throw ( SALOME::SALOME_Exception )
1483 Unexpect aCatch(SALOME_SalomeException);
1484 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1486 GEOM::GEOM_Gen_ptr engine = _this();
1488 GEOM_IInsertOperations_i* aServant =
1489 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1491 // activate the CORBA servant
1492 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1493 return operations._retn();
1496 //============================================================================
1497 // function : GetIMeasureOperations
1499 //============================================================================
1500 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1501 throw ( SALOME::SALOME_Exception )
1503 Unexpect aCatch(SALOME_SalomeException);
1504 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1506 GEOM::GEOM_Gen_ptr engine = _this();
1508 GEOM_IMeasureOperations_i* aServant =
1509 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1511 // activate the CORBA servant
1512 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1513 return operations._retn();
1516 //============================================================================
1517 // function : GetIGroupOperations
1519 //============================================================================
1520 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1521 throw ( SALOME::SALOME_Exception )
1523 Unexpect aCatch(SALOME_SalomeException);
1524 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1526 GEOM::GEOM_Gen_ptr engine = _this();
1528 GEOM_IGroupOperations_i* aServant =
1529 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1531 // activate the CORBA servant
1532 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1533 return operations._retn();
1536 //=============================================================================
1540 //=============================================================================
1541 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1542 const GEOM::ListOfLong& theIndices)
1544 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1545 return GEOM::GEOM_Object::_nil();
1546 CORBA::String_var entry = theMainShape->GetEntry();
1547 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1548 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1550 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1551 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1553 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1554 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1556 TCollection_AsciiString anEntry;
1557 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1558 return GetObject(anObject->GetDocID(), anEntry.ToCString());
1561 //=============================================================================
1565 //=============================================================================
1566 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1568 CORBA::String_var anEntry = theObject->GetEntry();
1569 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1570 if (anObject.IsNull()) return;
1571 _impl->RemoveObject(anObject);
1576 //=================================================================================
1577 // function : GetStringFromIOR()
1578 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
1579 //=================================================================================
1580 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1581 return _orb->object_to_string(theObject);
1585 //=================================================================================
1586 // function : GetIORFromString()
1587 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
1588 //=================================================================================
1589 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1590 GEOM::GEOM_Object_var aGeomObject;
1591 if(strcmp(stringIOR,"") != 0){
1592 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1593 if(!CORBA::is_nil(anObject))
1594 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
1596 return aGeomObject._retn();
1599 //=================================================================================
1600 // function : GetObject()
1602 //=================================================================================
1603 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1605 GEOM::GEOM_Object_var obj;
1606 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1607 if (handle_object.IsNull()) return obj._retn();
1609 TCollection_AsciiString stringIOR = handle_object->GetIOR();
1610 if (stringIOR.Length() > 1) {
1611 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1612 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1616 GEOM::GEOM_Gen_ptr engine = _this();
1617 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1619 obj = servant->_this();
1620 CORBA::String_var objStr = _orb->object_to_string(obj);
1621 TCollection_AsciiString anAscii( (char *)objStr.in() );
1622 handle_object->SetIOR( anAscii );
1626 //=================================================================================
1627 // function : hasObjectInfo()
1628 // purpose : shows if module provides information for its objects
1629 //=================================================================================
1630 bool GEOM_Gen_i::hasObjectInfo()
1635 //=================================================================================
1636 // function : getObjectInfo()
1637 // purpose : returns an information for a given object by its entry
1638 //=================================================================================
1639 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1641 GEOM::GEOM_Object_var aGeomObject;
1643 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1644 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1645 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1646 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1647 SALOMEDS::SObject_var aResultSObj;
1648 if (aSObj->ReferencedObject(aResultSObj))
1649 aSObj = aResultSObj;
1651 SALOMEDS::GenericAttribute_var anAttr;
1652 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1653 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1654 CORBA::String_var aVal = anIOR->Value();
1655 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1656 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1659 const char* aTypeInfo = "Object";
1660 if ( !aGeomObject->_is_nil() ) {
1661 GEOM::GEOM_IKindOfShape::shape_kind aKind;
1662 GEOM::ListOfLong_var anInts;
1663 GEOM::ListOfDouble_var aDbls;
1665 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1666 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1668 if ( anOp->IsDone() ) {
1670 case GEOM::GEOM_IKindOfShape::COMPOUND:
1671 aTypeInfo = "Compound";
1673 case GEOM::GEOM_IKindOfShape::COMPSOLID:
1674 aTypeInfo = "CompSolid";
1676 case GEOM::GEOM_IKindOfShape::SHELL:
1677 aTypeInfo = "Shell";
1679 case GEOM::GEOM_IKindOfShape::WIRE:
1680 if ( anInts[0] == 1 )
1681 aTypeInfo = "Closed Wire";
1682 else if ( anInts[0] == 2 )
1683 aTypeInfo = "Opened Wire";
1688 case GEOM::GEOM_IKindOfShape::SPHERE:
1689 aTypeInfo = "Sphere";
1691 case GEOM::GEOM_IKindOfShape::CYLINDER:
1692 aTypeInfo = "Cylinder";
1694 case GEOM::GEOM_IKindOfShape::BOX:
1695 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1698 case GEOM::GEOM_IKindOfShape::TORUS:
1699 aTypeInfo = "Torus";
1701 case GEOM::GEOM_IKindOfShape::CONE:
1704 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1705 aTypeInfo = "Polyhedron";
1707 case GEOM::GEOM_IKindOfShape::SOLID:
1708 aTypeInfo = "Solid";
1711 case GEOM::GEOM_IKindOfShape::SPHERE2D:
1712 aTypeInfo = "Spherical Face";
1714 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1715 aTypeInfo = "Cylindrical Face";
1717 case GEOM::GEOM_IKindOfShape::TORUS2D:
1718 aTypeInfo = "Toroidal Face";
1720 case GEOM::GEOM_IKindOfShape::CONE2D:
1721 aTypeInfo = "Conical Face";
1723 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1726 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1727 aTypeInfo = "Elliptical Face";
1729 case GEOM::GEOM_IKindOfShape::POLYGON:
1730 aTypeInfo = "Polygon";
1732 case GEOM::GEOM_IKindOfShape::PLANE:
1733 aTypeInfo = "Plane";
1735 case GEOM::GEOM_IKindOfShape::PLANAR:
1736 aTypeInfo = "Planar Face";
1738 case GEOM::GEOM_IKindOfShape::FACE:
1742 case GEOM::GEOM_IKindOfShape::CIRCLE:
1743 aTypeInfo = "Circle";
1745 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1748 case GEOM::GEOM_IKindOfShape::ELLIPSE:
1749 aTypeInfo = "Ellipse";
1751 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1752 aTypeInfo = "Arc Ellipse";
1754 case GEOM::GEOM_IKindOfShape::LINE:
1757 case GEOM::GEOM_IKindOfShape::SEGMENT:
1758 aTypeInfo = "Segment";
1760 case GEOM::GEOM_IKindOfShape::EDGE:
1763 case GEOM::GEOM_IKindOfShape::VERTEX:
1764 aTypeInfo = "Vertex";
1772 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1773 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1775 char* ret = CORBA::string_dup(anInfo);
1780 //=====================================================================================
1782 //=====================================================================================
1786 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1787 PortableServer::POA_ptr poa,
1788 PortableServer::ObjectId * contId,
1789 const char *instanceName,
1790 const char * interfaceName)
1792 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1793 // Don't understand the reason of this register ????
1794 // myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1795 return myGEOM_Gen_i->getId();