1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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
24 #pragma warning( disable:4786 )
27 #include <Standard_Stream.hxx>
29 #include "GEOM_Gen_i.hh"
30 #include "GEOM_Object_i.hh"
31 #include "GEOM_Field_i.hh"
32 #include "GEOM_version.h"
34 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "GEOM_Object_i.hh"
40 #include "GEOM_Object.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOM_ISubShape.hxx"
43 #include "GEOM_PythonDump.hxx"
44 #include "GEOMImpl_Types.hxx"
45 #include "GEOMImpl_CopyDriver.hxx"
46 #include "GEOMImpl_IInsertOperations.hxx"
47 #include "GEOM_wrap.hxx"
50 #include <BRep_Builder.hxx>
51 #include <BRepTools.hxx>
52 #include <TDF_Label.hxx>
53 #include <TDF_Tool.hxx>
54 #include <TDF_ChildIDIterator.hxx>
55 #include <TNaming_NamedShape.hxx>
56 #include <TDataStd_Name.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TColStd_HArray1OfInteger.hxx>
59 #include <TopAbs_ShapeEnum.hxx>
63 #include <SALOMEDS_Tool.hxx>
64 #include <SALOMEDS_wrap.hxx>
65 #include <SALOME_DataContainer_i.hxx>
66 #include <Basics_DirUtils.hxx>
79 #define LibHandle HMODULE
80 #define LoadLib( name ) LoadLibrary( name )
81 #define GetProc GetProcAddress
82 #define UnLoadLib( handle ) FreeLibrary( handle );
84 #define LibHandle void*
85 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
87 #define UnLoadLib( handle ) dlclose( handle );
90 //============================================================================
91 // function : GEOM_Gen_i()
92 // purpose : constructor to be called for servant creation.
93 //============================================================================
94 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
95 PortableServer::POA_ptr poa,
96 PortableServer::ObjectId* contId,
97 const char* instanceName,
98 const char* interfaceName) :
99 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
102 _id = _poa->activate_object(_thisObj);
103 name_service = new SALOME_NamingService(_orb);
105 _impl = new ::GEOMImpl_Gen;
107 //PAL10867: disable signals catching with "noexcepthandler" option
108 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
109 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
111 //work around PAL12004, PAL12628
112 //OSD::SetSignal( true );
116 char* envDisableFPE = getenv("DISABLE_FPE");
117 if (envDisableFPE && atoi(envDisableFPE))
122 OSD::SetSignal( raiseFPE );
126 //============================================================================
127 // function : ~GEOM_Gen_i()
128 // purpose : destructor
129 //============================================================================
130 GEOM_Gen_i::~GEOM_Gen_i() {
136 //============================================================================
137 // function : IORToLocalPersistentID()
139 //============================================================================
140 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
141 const char* IORString,
142 CORBA::Boolean isMultiFile,
143 CORBA::Boolean isASCII)
145 GEOM::GEOM_BaseObject_var anObject =
146 GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
147 if (!CORBA::is_nil(anObject)) {
148 return CORBA::string_dup(anObject->GetEntry());
154 //============================================================================
155 // function : LocalPersistentIDToIOR()
156 // purpose : Create/Load CORBA object from a persistent ref (an entry)
157 // : Used when a study is loaded
158 // : The IOR (IORName) of object created is returned
159 //============================================================================
160 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
161 const char* aLocalPersistentID,
162 CORBA::Boolean isMultiFile,
163 CORBA::Boolean isASCII)
165 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
167 Handle(GEOM_BaseObject) anObject =
168 _impl->GetObject(aStudy->StudyId(), aLocalPersistentID);
169 if ( !anObject.IsNull() )
171 TCollection_AsciiString anEntry;
172 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
173 GEOM::GEOM_BaseObject_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
175 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
176 return CORBA::string_dup(aPersRefString);
180 return CORBA::string_dup("");
184 //============================================================================
185 // function : CanPublishInStudy
187 //============================================================================
188 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
190 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
191 return !(anObject->_is_nil());
195 //============================================================================
196 // function : PublishInStudy
198 //============================================================================
199 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
200 SALOMEDS::SObject_ptr theSObject,
201 CORBA::Object_ptr theObject,
203 throw (SALOME::SALOME_Exception)
205 Unexpect aCatch(SALOME_SalomeException);
206 SALOMEDS::SObject_var aResultSO;
207 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
208 GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
209 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
210 if(aBaseObj->_is_nil()) return aResultSO;
212 SALOMEDS::GenericAttribute_var anAttr;
213 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
214 SALOMEDS::UseCaseBuilder_var useCaseBuilder = theStudy->GetUseCaseBuilder();
216 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
217 if (aFather->_is_nil()) {
218 aFather = aStudyBuilder->NewComponent("GEOM");
219 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
220 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
221 aName->SetValue("Geometry");
223 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
224 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
225 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
226 aPixMap->UnRegister();
227 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
228 // add component to the use case tree
229 // (to support tree representation customization and drag-n-drop)
230 useCaseBuilder->SetRootCurrent();
231 useCaseBuilder->Append( aFather ); // component object is added as the top level item
233 if (aFather->_is_nil()) return aResultSO;
235 if (CORBA::is_nil(theSObject)) {
236 aResultSO = aStudyBuilder->NewObject(aFather);
238 if (!theSObject->ReferencedObject(aResultSO))
239 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
240 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
242 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
243 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
245 TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
247 // BEGIN: try to find existed name for current shape
248 if ( !aShape->_is_nil() )
250 // recieve current TopoDS shape
251 CORBA::String_var entry = aShape->GetEntry();
252 Handle(GEOM_Object) aGShape = Handle(GEOM_Object)::DownCast
253 ( _impl->GetObject( aShape->GetStudyID(), entry ));
254 TopoDS_Shape TopoSh = aGShape->GetValue();
255 // find label of main shape
256 GEOM::GEOM_Object_var aMainSh = aShape;
257 while( !aMainSh->IsMainShape() ) {
258 aMainSh = aMainSh->GetMainShape();
260 entry = aMainSh->GetEntry();
261 Handle(GEOM_BaseObject) anObj = _impl->GetObject( aMainSh->GetStudyID(), entry );
262 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
264 // check all named shapes using iterator
265 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
267 for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
268 Handle(TNaming_NamedShape) anAttr =
269 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
270 if (anAttr.IsNull()) continue;
271 TopoDS_Shape S = anAttr->Get();
272 if (S.IsEqual(TopoSh)) {
273 TDF_Label L = anAttr->Label();
274 Handle(TDataStd_Name) aName;
275 if (L.FindAttribute(TDataStd_Name::GetID(), aName))
276 anObjectName = aName->Get();
280 // END: try to find existed name for current shape
282 CORBA::Long mytype=aBaseObj->GetType();
283 if ( mytype == GEOM_GROUP ) {
284 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
285 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
287 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
288 aNamePrefix = "Group_Of_Vertices_";
291 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
292 aNamePrefix = "Group_Of_Edges_";
295 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
296 aNamePrefix = "Group_Of_Faces_";
299 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
300 aNamePrefix = "Group_Of_Solids_";
303 } else if ( mytype == GEOM_MARKER ) {
304 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
305 aNamePrefix = "LocalCS_";
306 } else if ( mytype > ADVANCED_BASE ) {
308 sprintf( buf, "%d", aBaseObj->GetType() );
309 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
310 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
311 aNamePrefix = "Advanced_";
312 } else if ( mytype == GEOM_FIELD ) {
313 aNamePrefix = "Field_";
314 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
315 if ( !aField->_is_nil() )
316 switch( aField->GetDimension() ) {
318 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
320 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
322 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
324 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
326 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
328 } else if ( mytype == GEOM_FIELD_STEP ) {
329 aNamePrefix = "Step_";
330 } else if ( !aShape->_is_nil() ) {
331 GEOM::shape_type myshapetype=aShape->GetShapeType();
332 if ( myshapetype == GEOM::COMPOUND ) {
333 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
334 aNamePrefix = "Compound_";
335 } else if ( myshapetype == GEOM::COMPSOLID ) {
336 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
337 aNamePrefix = "Compsolid_";
338 } else if ( myshapetype == GEOM::SOLID ) {
339 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
340 aNamePrefix = "Solid_";
341 } else if ( myshapetype == GEOM::SHELL ) {
342 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
343 aNamePrefix = "Shell_";
344 } else if ( myshapetype == GEOM::FACE ) {
345 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
346 aNamePrefix = "Face_";
347 } else if ( myshapetype == GEOM::WIRE ) {
348 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
349 aNamePrefix = "Wire_";
350 } else if ( myshapetype == GEOM::EDGE ) {
351 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
352 aNamePrefix = "Edge_";
353 } else if ( myshapetype == GEOM::VERTEX ) {
354 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
355 aNamePrefix = "Vertex_";
358 if ( anObjectName.IsEmpty() )
360 //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
361 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
363 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
364 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
365 // of objects in the study, but compute a number of objects with the same prefix
366 // and build a new name as Prefix_N+1
367 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
368 int i = 0; // (WITH EMPTY NEW NAME)
369 SALOMEDS::SObject_var obj;
371 anObjectName = aNamePrefix + TCollection_AsciiString(++i);
372 obj = theStudy->FindObject( anObjectName.ToCString() );
374 while ( !obj->_is_nil() );
376 else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
377 anObjectName = theName;
381 //Set the study entry as a name of the published GEOM_Object
382 CORBA::String_var anID = aResultSO->GetID();
383 aBaseObj->SetStudyEntry(anID.in());
385 //Set a name of the added shape
386 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
388 //Set NoteBook variables used in the object creation
389 TCollection_AsciiString aVars;
390 CORBA::String_var aString=aBaseObj->GetParameters();
391 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString);
392 for(int i = 0, n = aSections->length(); i < n; i++) {
393 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
394 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
395 if(theStudy->IsVariable(aListOfVars[j].in()))
396 aVars += aListOfVars[j].in();
403 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
405 aFather->UnRegister();
407 //Set a name of the GEOM object
408 aBaseObj->SetName(anObjectName.ToCString());
410 // add object to the use case tree
411 // (to support tree representation customization and drag-n-drop)
412 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
414 return aResultSO._retn();
417 //============================================================================
418 // function : CreateAndPublishGroup
419 // purpose : auxilary for PublishNamedShapesInStudy
420 //============================================================================
421 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
422 GEOM::GEOM_Object_var theMainShape,
423 const TopTools_IndexedMapOfShape& anIndices,
424 const TopTools_SequenceOfShape& SeqS,
425 const TColStd_SequenceOfAsciiString& SeqN,
426 const Standard_CString& GrName,
427 GEOM::ListOfGO_var aResList)
429 CORBA::String_var entry = theMainShape->GetEntry();
430 //Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
431 Handle(TColStd_HArray1OfInteger) anArray;
432 if(SeqS.Length()>0) {
434 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
435 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
436 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
437 //CORBA::String_var GrEntry = GrObj->GetEntry();
438 //Handle(GEOM_Object) HGrObj = _impl->GetObject(GrObj->GetStudyID(), GrEntry);
440 //Handle(GEOM_Object) anObj;
441 for(int i=1; i<=SeqS.Length(); i++) {
442 TopoDS_Shape aValue = SeqS.Value(i);
443 //anArray = new TColStd_HArray1OfInteger(1,1);
444 Standard_Integer anIndex = anIndices.FindIndex(aValue);
445 //anArray->SetValue(1, anIndex);
446 GOp->AddObject(GrObj,anIndex);
447 //anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
448 //if (anObj.IsNull()) continue;
449 //Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
450 //if (aFunction.IsNull()) continue;
451 //GEOM_ISubShape aSSI(aFunction);
452 //aSSI.SetMainShape(aMainShape->GetLastFunction());
453 //aSSI.SetIndices(anArray);
454 //aFunction->SetValue(aValue);
455 //GOp->UnionIDs(GrObj, anIndex);
456 //SALOMEDS::SObject_var aResultSO;
457 //TCollection_AsciiString anEntry;
458 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
459 //GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
460 //AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
466 //============================================================================
467 // function : PublishNamedShapesInStudy
469 //============================================================================
470 GEOM::ListOfGO* GEOM_Gen_i::
471 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
472 //SALOMEDS::SObject_ptr theSObject,
473 CORBA::Object_ptr theObject)
475 //Unexpect aCatch(SALOME_SalomeException);
476 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
478 //CORBA::Object_var theObject = theSObject->GetObject();
479 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
480 if(theMainShape->_is_nil()) return aResList._retn();
482 CORBA::String_var entry = theMainShape->GetEntry();
483 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
484 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
485 if (aMainShape.IsNull()) return aResList._retn();
486 TopoDS_Shape MainSh = aMainShape->GetValue();
488 TDF_Label aMainLbl = aMainShape->GetEntry();
489 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
490 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
491 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
492 for(; anIt.More(); anIt.Next()) {
493 Handle(TNaming_NamedShape) anAttr =
494 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
495 if(anAttr.IsNull()) continue;
496 TopoDS_Shape S = anAttr->Get();
497 TDF_Label L = anAttr->Label();
498 //if(S.IsEqual(MainSh)) continue;
499 Handle(TDataStd_Name) aName;
500 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
501 TCollection_ExtendedString EName = aName->Get();
502 if(S.ShapeType()==TopAbs_SOLID) {
504 SolidSeqN.Append(aName->Get());
506 else if(S.ShapeType()==TopAbs_FACE) {
508 FaceSeqN.Append(aName->Get());
510 else if(S.ShapeType()==TopAbs_EDGE) {
512 EdgeSeqN.Append(aName->Get());
514 else if(S.ShapeType()==TopAbs_VERTEX) {
516 VertSeqN.Append(aName->Get());
521 TopTools_IndexedMapOfShape anIndices;
522 TopExp::MapShapes(MainSh, anIndices);
524 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
525 "Group_Of_Named_Solids", aResList);
527 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
528 "Group_Of_Named_Faces", aResList);
530 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
531 "Group_Of_Named_Edges", aResList);
533 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
534 "Group_Of_Named_Vertices", aResList);
536 return aResList._retn();
540 //============================================================================
542 // purpose : save OCAF/Geom document
543 //============================================================================
544 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
547 SALOMEDS::TMPFile_var aStreamFile;
548 // Get a temporary directory to store a file
549 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
551 // OCCT BUG: cannot save a document (in current folder)
552 // if directory name is empty
553 if (aTmpDir.size() == 0) {
561 // Create a list to store names of created files
562 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
564 // Prepare a file name to open
565 TCollection_AsciiString aNameWithExt("");
567 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
568 (theComponent->GetStudy()->URL())).c_str());
569 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
570 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
571 // Build a full file name of temporary file
572 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
573 // Save GEOM component in this file
574 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
575 // Conver a file to the byte stream
576 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
577 // Remove the created file and tmp directory
578 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
580 // Return the created byte stream
581 return aStreamFile._retn();
585 //============================================================================
586 // function : SaveASCII()
588 //============================================================================
589 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
592 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
593 return aStreamFile._retn();
597 //============================================================================
600 //============================================================================
601 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
602 const SALOMEDS::TMPFile& theStream,
606 if (theStream.length() <= 9) {
607 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
611 // Get a temporary directory for a file
612 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
614 // OCCT BUG: cannot load a document (from current folder)
615 // if directory name is empty
616 if (aTmpDir.size() == 0) {
624 // Conver the byte stream theStream to a file and place it in tmp directory
625 SALOMEDS::ListOfFileNames_var aSeq =
626 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
628 // Prepare a file name to open
629 TCollection_AsciiString aNameWithExt("");
630 SALOMEDS::Study_var study = theComponent->GetStudy();
632 CORBA::String_var url = study->URL();
633 aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str();
635 aNameWithExt += "_GEOM.sgd";
636 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
639 if (!_impl->Load(study->StudyId(),(char*) aFullName.ToCString())) return false;
641 // Remove the created file and tmp directory
642 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
644 // creation of tree nodes for all data objects in the study
645 // to support tree representation customization and drag-n-drop:
646 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
647 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
648 useCaseBuilder->SetRootCurrent();
649 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
652 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
653 for ( it->InitEx(true); it->More(); it->Next() ) {
654 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
655 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
663 //============================================================================
664 // function : LoadASCII()
666 //============================================================================
667 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
668 const SALOMEDS::TMPFile& theStream,
671 return Load(theComponent, theStream, theURL, isMultiFile);
675 //============================================================================
676 // function : Close()
678 //============================================================================
679 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
681 SALOMEDS::Study_var aStudy= theComponent->GetStudy();
682 _impl->Close(aStudy->StudyId());
685 //============================================================================
686 // function : CanCopy()
688 //============================================================================
689 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
690 // Try to retrieve known by Geometry component GEOM_Object by given IOR
691 SALOMEDS::GenericAttribute_var anAttr;
692 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
694 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
696 CORBA::String_var aString=anIOR->Value();
698 CORBA::Object_var anObj = _orb->string_to_object(aString);
699 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
700 // If the object is null one it can't be copied: return false
701 if (anObject->_is_nil()) return false;
705 //============================================================================
706 // function : CopyFrom()
708 //============================================================================
709 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
711 // Declare a sequence of the byte to store the copied object
712 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
714 // Try to get GEOM_Object object by given SObject
715 SALOMEDS::GenericAttribute_var anAttr;
716 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
717 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
718 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
719 if (anObject->_is_nil()) return aStreamFile._retn();
721 aStreamFile = anObject->GetShapeStream();
723 // Assign an ID the type of GEOM_Object
724 theObjectID = anObject->GetType();
726 // Return created TMPFile
727 return aStreamFile._retn();
730 //============================================================================
731 // function : CanPaste()
733 //============================================================================
734 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
735 // The Geometry component can paste only objects copied by Geometry component
736 // and with the object type = 1
737 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
741 //============================================================================
742 // function : PasteInto()
744 //============================================================================
745 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
746 CORBA::Long theObjectID,
747 SALOMEDS::SObject_ptr theObject) {
748 // Find the current Study and StudyBuilder
749 SALOMEDS::Study_var aStudy = theObject->GetStudy();
750 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
751 SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
752 SALOMEDS::SObject_var aNewSO;
753 // Retrieve a TopoDS_Shape from byte stream
754 TopoDS_Shape aTopology;
755 std::istringstream aStreamedBrep((char*) &theStream[0]);
756 BRep_Builder aBuilder;
758 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
759 } catch (Standard_Failure) {
760 return aNewSO._retn();
763 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
764 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
765 aNewSO = aStudyBuilder->NewObject(theObject);
766 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
769 //Create a new GEOM_Object
770 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
771 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
772 aFunction->SetValue(aTopology);
774 TCollection_AsciiString anEntry;
775 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
776 GEOM::GEOM_BaseObject_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
778 //Set the study entry of the published GEOM_Object
779 obj->SetStudyEntry(aNewSO->GetID());
781 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
782 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
783 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
784 CORBA::String_var objStr = _orb->object_to_string(obj);
785 anIOR->SetValue(objStr.in());
788 // add object to the use case tree
789 // (to support tree representation customization and drag-n-drop)
790 anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
792 // Return the created in the Study SObject
793 return aNewSO._retn();
796 //============================================================================
797 // function : ComponentDataType()
799 //============================================================================
800 char* GEOM_Gen_i::ComponentDataType()
802 return CORBA::string_dup("GEOM");
805 //============================================================================
806 // function : AddInStudy
808 //============================================================================
809 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
810 GEOM::GEOM_BaseObject_ptr theObject,
812 GEOM::GEOM_BaseObject_ptr theFather)
814 SALOMEDS::SObject_var aResultSO;
815 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
817 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
818 CORBA::String_var IOR;
820 if(!theFather->_is_nil()) {
821 IOR = _orb->object_to_string(theFather);
822 SALOMEDS::SObject_wrap aFatherSO = theStudy->FindObjectIOR(IOR.in());
823 if(aFatherSO->_is_nil()) return aResultSO._retn();
824 aResultSO = aStudyBuilder->NewObject(aFatherSO);
825 //aStudyBuilder->Addreference(aResultSO, aResultSO);
828 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
829 if(aResultSO->_is_nil()) return aResultSO._retn();
831 GEOM::ListOfGBO_var aList = theObject->GetDependency();
832 Standard_Integer aLength = aList->length();
833 if(aLength < 1) return aResultSO._retn();
835 //Publish the arguments
836 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
837 for(Standard_Integer i = 0; i< aLength; i++) {
838 GEOM::GEOM_BaseObject_var anObject = aList[i];
839 if(anObject->_is_nil()) continue;
840 IOR = _orb->object_to_string(anObject);
841 SALOMEDS::SObject_wrap aSO = theStudy->FindObjectIOR(IOR.in());
842 if(aSO->_is_nil()) continue;
843 CORBA::String_var anID = aSO->GetID();
844 if ( aPrevID == anID.in() ) continue;
846 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
847 aStudyBuilder->Addreference(aSubSO, aSO);
848 theStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
851 return aResultSO._retn();
854 //============================================================================
855 // function : RestoreSubShapesO
856 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
857 // To be used from python scripts out of geompy.addToStudy (non-default usage)
858 //============================================================================
859 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
860 GEOM::GEOM_Object_ptr theObject,
861 const GEOM::ListOfGO& theArgs,
862 GEOM::find_shape_method theFindMethod,
863 CORBA::Boolean theInheritFirstArg,
864 CORBA::Boolean theAddPrefix)
866 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
867 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
868 return aParts._retn();
870 // find SObject in the study if it is already published
871 CORBA::String_var anIORo = _orb->object_to_string(theObject);
872 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
873 //PTv, IMP 0020001, The salome object <aSO>
874 // is not obligatory in case of invokation from script
875 // if (CORBA::is_nil(aSO))
876 // return aParts._retn();
878 aParts = RestoreSubShapes(theStudy, theObject, aSO, theArgs,
879 theFindMethod, theInheritFirstArg, theAddPrefix);
880 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
881 return aParts._retn();
884 //============================================================================
885 // function : RestoreGivenSubShapesO
886 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
887 // To be used from python scripts, generated by Dump Python.
888 //============================================================================
889 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (SALOMEDS::Study_ptr theStudy,
890 GEOM::GEOM_Object_ptr theObject,
891 const GEOM::ListOfGO& theArgs,
892 GEOM::find_shape_method theFindMethod,
893 CORBA::Boolean theInheritFirstArg,
894 CORBA::Boolean theAddPrefix)
896 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
897 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
898 return aParts._retn();
900 // find SObject in the study if it is already published
901 CORBA::String_var anIORo = _orb->object_to_string(theObject);
902 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
903 //PTv, IMP 0020001, The salome object <aSO>
904 // is not obligatory in case of invokation from script
905 // if (CORBA::is_nil(aSO))
906 // return aParts._retn();
908 aParts = RestoreGivenSubShapes(theStudy, theObject, aSO, theArgs,
909 theFindMethod, theInheritFirstArg, theAddPrefix);
910 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
911 return aParts._retn();
914 //============================================================================
915 // function : RestoreSubShapesSO
916 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
917 // To be used from GUI and from geompy.addToStudy
918 //============================================================================
919 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
920 SALOMEDS::SObject_ptr theSObject,
921 const GEOM::ListOfGO& theArgs,
922 GEOM::find_shape_method theFindMethod,
923 CORBA::Boolean theInheritFirstArg,
924 CORBA::Boolean theAddPrefix)
926 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
927 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
928 return aParts._retn();
930 SALOMEDS::GenericAttribute_var anAttr;
931 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
932 return aParts._retn();
934 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
935 CORBA::String_var anIORso = anAttrIOR->Value();
937 // get Object from SObject
938 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
939 if (CORBA::is_nil(anO))
940 return aParts._retn();
942 aParts = RestoreSubShapes(theStudy, anO, theSObject, theArgs,
943 theFindMethod, theInheritFirstArg, theAddPrefix);
944 return aParts._retn();
947 //============================================================================
948 // function : addToListOfGO
949 // purpose : static local function
950 //============================================================================
951 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
952 GEOM::ListOfGO& theList )
954 const int oldLen = theList.length();
955 theList.length(oldLen + 1);
956 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
959 //============================================================================
960 // function : addToListOfGO
961 // purpose : static local function
962 //============================================================================
963 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
964 GEOM::ListOfGO& theTrgList )
966 const int oldLen = theTrgList.length();
967 const int srcLen = theSrcList.length();
968 theTrgList.length(oldLen + srcLen);
969 for( int i = 0; i < srcLen; i++ )
970 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
973 //============================================================================
974 // function : RestoreSubShapes
975 // purpose : Private method. Works only if both theObject and theSObject
976 // are defined, and does not check, if they correspond to each other.
977 //============================================================================
978 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy,
979 GEOM::GEOM_Object_ptr theObject,
980 SALOMEDS::SObject_ptr theSObject,
981 const GEOM::ListOfGO& theArgs,
982 GEOM::find_shape_method theFindMethod,
983 CORBA::Boolean theInheritFirstArg,
984 CORBA::Boolean theAddPrefix)
986 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
987 //PTv, IMP 0020001, The salome object <theSObject>
988 // is not obligatory in case of invokation from script
989 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
990 return aParts._retn();
992 // For Dump Python (mantis issue 0020768)
993 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
995 // Arguments to be published
996 GEOM::ListOfGO_var aList;
998 // If theArgs list is empty, we try to publish all arguments,
999 // otherwise publish only passed args
1000 Standard_Integer nbArgsActual = -1; // -1 means unknown
1001 Standard_Integer aLength = theArgs.length();
1003 aList = new GEOM::ListOfGO;
1004 aList->length(aLength);
1005 for (int i = 0; i < aLength; i++) {
1006 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1010 // Get all arguments
1011 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1012 aLength = boList->length();
1013 aList = new GEOM::ListOfGO;
1014 aList->length(aLength);
1015 for (int i = 0; i < aLength; i++)
1016 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1017 nbArgsActual = aLength;
1021 return aParts._retn();
1023 if (theInheritFirstArg || (nbArgsActual == 1)) {
1024 // Do not publish argument's reflection,
1025 // but only reconstruct its published sub-shapes
1027 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1028 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1030 // remember restored objects for Python Dump
1031 addToListOfGO(aList[0], anOutArgs);
1033 aParts = RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1034 anOutArgs, theFindMethod, theAddPrefix);
1036 // set the color of the transformed shape to the color of initial shape
1037 theObject->SetColor(aList[0]->GetColor());
1039 if (theObject->GetShapeType() == GEOM::VERTEX) {
1040 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1041 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1042 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1045 anArgSO->UnRegister();
1048 // Get interface, containing method, which we will use to reconstruct sub-shapes
1049 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1050 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1051 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1053 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1054 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1056 // Reconstruct arguments and tree of sub-shapes of the arguments
1057 CORBA::String_var anIOR;
1058 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1059 for (Standard_Integer i = 0; i < aLength; i++)
1061 GEOM::GEOM_Object_var anArgO = aList[i];
1062 if (!CORBA::is_nil(anArgO)) {
1063 anIOR = _orb->object_to_string(anArgO);
1064 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1065 TCollection_AsciiString anArgName;
1066 if (CORBA::is_nil(anArgSO)) {
1068 anArgName += TCollection_AsciiString(i);
1071 anArgName = anArgSO->GetName();
1074 // Find a sub-shape of theObject in place of the argument
1075 GEOM::GEOM_Object_var aSubO;
1076 switch (theFindMethod) {
1077 case GEOM::FSM_GetInPlace:
1080 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1083 case GEOM::FSM_MultiTransformed:
1085 // Only for Multi-transformations
1086 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1087 if (!CORBA::is_nil(anArgOTrsf)) {
1088 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1089 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1090 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1091 anArgOTrsfFun->SetDescription("");
1092 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1095 Handle(GEOM_Function) anOFun = theObject->GetLastFunction();
1096 if (!anOFun.IsNull()) {
1097 CORBA::String_var entryArg = anArgO->GetEntry();
1098 Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg);
1099 if (!anArgOImpl.IsNull()) {
1100 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1101 TopoDS_Shape aMultiArgShape;
1102 //GEOM::GEOM_Object_var anArgOMulti; // ???
1103 switch (anOFun->GetType()) {
1106 GEOMImpl_ITranslate aTI (anOFun);
1107 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1108 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1113 GEOMImpl_ITranslate aTI (anOFun);
1114 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1119 GEOMImpl_IRotate aTI (anOFun);
1120 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1125 GEOMImpl_IRotate aTI (anOFun);
1126 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1132 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1133 Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1134 anArgOMultiFun->SetDescription("");
1135 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1141 case GEOM::FSM_Transformed:
1143 // transformation, cannot use GetInPlace, operate with indices
1144 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1145 if (anIDs->length() > 1) {
1147 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1148 if (!CORBA::is_nil(aSubO))
1149 aGroupOp->UnionIDs(aSubO, anIDs);
1151 else if (anIDs->length() > 0) {
1153 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1157 case GEOM::FSM_GetSame:
1160 aSubO = aShapesOp->GetSame(theObject, anArgO);
1163 case GEOM::FSM_GetShapesOnShape:
1165 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1166 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1167 (short)GEOM::SOLID, GEOM::ST_ONIN);
1170 case GEOM::FSM_GetInPlaceByHistory:
1172 // Use GetInPlaceByHistory
1173 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1180 if (!CORBA::is_nil(aSubO)) {
1181 // remember restored objects for Python Dump
1182 addToListOfGO(anArgO, anOutArgs);
1184 // add to parts list
1185 addToListOfGO( aSubO, aParts );
1187 // Publish the sub-shape
1188 SALOMEDS::SObject_var aSubSO;
1189 if (!CORBA::is_nil(theSObject)) {
1190 TCollection_AsciiString aSubName;
1194 aSubName += anArgName;
1195 aSubSO = aStudyBuilder->NewObject(theSObject);
1196 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1198 aSubO->SetColor(anArgO->GetColor());
1200 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1201 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1202 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1203 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1207 if (!CORBA::is_nil(anArgSO)) {
1208 // Restore published sub-shapes of the argument
1209 GEOM::ListOfGO_var aSubParts;
1210 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1211 // pass theObject, because only it has the history
1212 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1213 theObject, anOutArgs, theFindMethod, theAddPrefix);
1215 aSubParts = RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1216 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1217 // add to parts list
1218 addToListOfGO( aSubParts, aParts );
1221 else { // GetInPlace failed, try to build from published parts
1222 if (!CORBA::is_nil(anArgSO)) {
1223 SALOMEDS::SObject_var aSubSO;
1224 if (!CORBA::is_nil(theSObject))
1225 aSubSO = aStudyBuilder->NewObject(theSObject);
1227 // Restore published sub-shapes of the argument
1228 GEOM::ListOfGO_var aSubParts =
1229 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1230 theObject, anOutArgs, theFindMethod, theAddPrefix);
1232 // add to parts list
1233 addToListOfGO( aSubParts, aParts );
1235 if (aSubParts->length() > 0) {
1236 // remember restored objects for Python Dump
1237 addToListOfGO(anArgO, anOutArgs);
1239 // try to build an argument from a set of its sub-shapes,
1240 // that published and will be reconstructed
1241 if (aSubParts->length() > 1) {
1242 aSubO = aShapesOp->MakeCompound(aSubParts);
1243 // add to parts list
1244 addToListOfGO( aSubO, aParts );
1247 aSubO = aSubParts[0];
1249 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1250 // Publish the sub-shape
1251 TCollection_AsciiString aSubName;
1253 aSubName = "from_parts_of_";
1255 aSubName += anArgName;
1256 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1258 aSubO->SetColor(anArgO->GetColor());
1260 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1261 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1262 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1263 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1267 else if (!CORBA::is_nil(aSubSO)) {
1268 // remove created aSubSO, because no parts have been found
1269 aStudyBuilder->RemoveObject(aSubSO);
1272 } // try to build from published parts
1273 anArgSO->UnRegister();
1275 } // process arguments
1277 std::set<std::string> anObjEntryMap;
1278 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1280 int nb = aParts->length();
1281 aResParts->length(nb);
1284 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1285 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1286 GEOM::TPythonDump pd (aFunction, true);
1289 for ( ; i < nb; i++ )
1291 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1292 if (CORBA::is_nil(anObj))
1294 char* anEntry = anObj->GetEntry();
1295 if (anObjEntryMap.count(anEntry))
1296 continue; // already treated
1297 anObjEntryMap.insert(anEntry);
1298 aResParts[nbRes++] = anObj;
1299 // clear python dump of object
1300 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1301 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1302 if ( !anObjFun.IsNull() )
1303 anObjFun->SetDescription( "" );
1309 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1310 //i = 0; nb = theArgs.length(); j = 0;
1311 i = 0; nb = anOutArgs->length(); j = 0;
1312 for ( ; i < nb; i++ )
1314 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1315 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1316 if (CORBA::is_nil(anObj))
1318 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1324 pd <<"]" << ", " <<"GEOM.";
1325 switch (theFindMethod) {
1326 case GEOM::FSM_GetInPlace:
1327 pd << "FSM_GetInPlace"; break;
1328 case GEOM::FSM_MultiTransformed:
1329 pd << "FSM_MultiTransformed"; break;
1330 case GEOM::FSM_Transformed:
1331 pd << "FSM_Transformed"; break;
1332 case GEOM::FSM_GetSame:
1333 pd << "FSM_GetSame"; break;
1334 case GEOM::FSM_GetShapesOnShape:
1335 pd << "FSM_GetShapesOnShape"; break;
1336 case GEOM::FSM_GetInPlaceByHistory:
1338 pd << "FSM_GetInPlaceByHistory"; break;
1340 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1342 aResParts->length(nbRes);
1343 return aResParts._retn();
1346 //============================================================================
1347 // function : RestoreSubShapesOneLevel
1348 // purpose : Private method
1349 //============================================================================
1350 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1351 SALOMEDS::SObject_ptr theOldSO,
1352 SALOMEDS::SObject_ptr theNewSO,
1353 GEOM::GEOM_Object_ptr theNewO,
1354 GEOM::ListOfGO& theOutArgs,
1355 GEOM::find_shape_method theFindMethod,
1356 CORBA::Boolean theAddPrefix)
1359 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1360 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1361 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1362 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1363 return aParts._retn();
1365 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1367 // Get interface, containing method, which we will use to reconstruct sub-shapes
1368 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1369 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1370 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1372 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1373 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1375 // Reconstruct published sub-shapes
1376 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1379 for (it->Init(); it->More(); it->Next()) {
1382 aParts->length(aLen);
1384 for (it->Init(); it->More(); it->Next()) {
1385 SALOMEDS::SObject_var anOldSubSO = it->Value();
1387 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1389 SALOMEDS::GenericAttribute_var anAttr;
1390 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1391 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1392 GEOM::GEOM_Object_var anOldSubO =
1393 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1394 if (!CORBA::is_nil(anOldSubO)) {
1395 // Find a sub-shape of theNewO in place of anOldSubO
1396 GEOM::GEOM_Object_var aNewSubO;
1397 switch (theFindMethod) {
1398 case GEOM::FSM_GetInPlace:
1401 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1404 case GEOM::FSM_MultiTransformed:
1406 // Only for Multi-transformations
1407 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1408 if (!CORBA::is_nil(anArgOTrsf)) {
1409 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1410 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1411 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1412 anArgOTrsfFun->SetDescription("");
1413 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1417 case GEOM::FSM_Transformed:
1419 // transformation, cannot use GetInPlace, operate with indices
1420 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1421 if (anIDs->length() > 1) {
1423 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1424 if (!CORBA::is_nil(aNewSubO))
1425 aGroupOp->UnionIDs(aNewSubO, anIDs);
1429 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1433 case GEOM::FSM_GetSame:
1436 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1439 case GEOM::FSM_GetShapesOnShape:
1441 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1442 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1443 (short)GEOM::SOLID, GEOM::ST_ONIN);
1446 case GEOM::FSM_GetInPlaceByHistory:
1448 // Use GetInPlaceByHistory
1449 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1456 if (!CORBA::is_nil(aNewSubO)) {
1457 // remember restored objects for Python Dump
1458 addToListOfGO(anOldSubO, theOutArgs);
1460 // add the part to the list
1461 aParts[i] = aNewSubO;
1463 // add to parts list
1464 addToListOfGO( aNewSubO, aNewParts );
1466 SALOMEDS::SObject_var aNewSubSO;
1467 if (!CORBA::is_nil(theNewSO)) {
1468 // Publish the sub-shape
1469 TCollection_AsciiString aSubName;
1473 aSubName += anArgName;
1474 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1475 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1477 aNewSubO->SetColor(anOldSubO->GetColor());
1479 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1480 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1481 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1482 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1485 // Restore published sub-shapes of the argument
1486 GEOM::ListOfGO_var aSubParts;
1487 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1488 // pass the main shape as Object, because only it has the history
1489 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1490 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1492 aSubParts = RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1493 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1494 // add to parts list
1495 addToListOfGO( aSubParts, aNewParts );
1497 else { // GetInPlace failed, try to build from published parts
1498 SALOMEDS::SObject_var aNewSubSO;
1499 if (!CORBA::is_nil(theNewSO))
1500 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1502 // Restore published sub-shapes of the argument
1503 GEOM::ListOfGO_var aSubParts =
1504 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
1505 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1506 // add to parts list
1507 addToListOfGO( aSubParts, aNewParts );
1509 if (aSubParts->length() > 0) {
1510 // remember restored objects for Python Dump
1511 addToListOfGO(anOldSubO, theOutArgs);
1513 // try to build an object from a set of its sub-shapes,
1514 // that published and will be reconstructed
1515 if (aSubParts->length() > 1) {
1516 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1517 // add to parts list
1518 addToListOfGO( aNewSubO, aNewParts );
1521 aNewSubO = aSubParts[0];
1524 if (!CORBA::is_nil(aNewSubO)) {
1525 // add the part to the list
1526 aSubParts[i] = aNewSubO;
1529 // Publish the sub-shape
1530 if (!CORBA::is_nil(aNewSubSO)) {
1531 TCollection_AsciiString aSubName;
1533 aSubName = "from_parts_of_";
1535 aSubName += anArgName;
1536 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1538 aNewSubO->SetColor(anOldSubO->GetColor());
1540 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1541 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1542 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1543 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1548 else if (!CORBA::is_nil(aNewSubSO)) {
1549 // remove created aSubSO, because no parts have been found
1550 aStudyBuilder->RemoveObject(aNewSubSO);
1552 } // try to build from published parts
1555 } // iterate on published sub-shapes
1558 // add to parts list
1559 addToListOfGO( aNewParts, aParts );
1560 return aParts._retn();
1563 //============================================================================
1564 // function : RestoreGivenSubShapes
1565 // purpose : Private method. Works only if both theObject and theSObject
1566 // are defined, and does not check, if they correspond to each other.
1567 // List theArgs in this case contains not only operation arguments,
1568 // but also all subshapes, which must be published.
1569 //============================================================================
1570 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStudy,
1571 GEOM::GEOM_Object_ptr theObject,
1572 SALOMEDS::SObject_ptr theSObject,
1573 const GEOM::ListOfGO& theArgs,
1574 GEOM::find_shape_method theFindMethod,
1575 CORBA::Boolean theInheritFirstArg,
1576 CORBA::Boolean theAddPrefix)
1578 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1579 //PTv, IMP 0020001, The salome object <theSObject>
1580 // is not obligatory in case of invokation from script
1581 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1582 return aParts._retn();
1584 // If theArgs list is empty, nothing to do
1585 Standard_Integer aLength = theArgs.length();
1587 return aParts._retn();
1589 // Get all arguments
1590 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1591 Standard_Integer nbArgsActual = anOpArgsList->length();
1593 // If anOpArgsList list is empty, nothing to do
1594 if (nbArgsActual == 0)
1595 return aParts._retn();
1597 // Entries of arguments and subshapes
1598 std::set<std::string> anArgs;
1599 for (int i = 0; i < aLength; i++) {
1600 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1601 anArgs.insert(anEntry.in());
1604 // Arguments to be published
1605 // We try to publish all arguments, that are in theArgs list
1606 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1607 aList->length(nbArgsActual);
1610 for (int j = 0; j < nbArgsActual; j++) {
1611 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1612 if (anArgs.count(anEntry.in())) {
1613 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1618 //aList->length(nbArgsActual);
1620 if (nbArgsActual < 1)
1621 return aParts._retn();
1623 if (theInheritFirstArg || (nbArgsActual == 1)) {
1624 // Do not publish argument's reflection,
1625 // but only reconstruct its published sub-shapes
1627 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1628 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1630 aParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject,
1631 anArgs, theFindMethod, theAddPrefix);
1633 // set the color of the transformed shape to the color of initial shape
1634 theObject->SetColor(aList[0]->GetColor());
1636 if (theObject->GetShapeType() == GEOM::VERTEX) {
1637 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1638 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1639 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1642 anArgSO->UnRegister();
1645 // Get interface, containing method, which we will use to reconstruct sub-shapes
1646 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1647 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1648 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1650 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1651 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1653 // Reconstruct arguments and tree of sub-shapes of the arguments
1654 CORBA::String_var anIOR;
1655 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1656 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1658 GEOM::GEOM_Object_var anArgO = aList[i];
1659 if (!CORBA::is_nil(anArgO)) {
1660 anIOR = _orb->object_to_string(anArgO);
1661 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
1662 TCollection_AsciiString anArgName;
1663 if (CORBA::is_nil(anArgSO)) {
1665 anArgName += TCollection_AsciiString(i);
1668 anArgName = anArgSO->GetName();
1671 // Find a sub-shape of theObject in place of the argument
1672 GEOM::GEOM_Object_var aSubO;
1673 switch (theFindMethod) {
1674 case GEOM::FSM_GetInPlace:
1677 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1680 case GEOM::FSM_MultiTransformed:
1682 // Only for Multi-transformations
1683 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1684 if (!CORBA::is_nil(anArgOTrsf)) {
1685 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1686 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1687 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1688 anArgOTrsfFun->SetDescription("");
1689 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1693 case GEOM::FSM_Transformed:
1695 // transformation, cannot use GetInPlace, operate with indices
1696 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1697 if (anIDs->length() > 1) {
1699 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1700 if (!CORBA::is_nil(aSubO))
1701 aGroupOp->UnionIDs(aSubO, anIDs);
1703 else if (anIDs->length() > 0) {
1705 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1709 case GEOM::FSM_GetSame:
1712 aSubO = aShapesOp->GetSame(theObject, anArgO);
1715 case GEOM::FSM_GetShapesOnShape:
1717 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1718 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1719 (short)GEOM::SOLID, GEOM::ST_ONIN);
1722 case GEOM::FSM_GetInPlaceByHistory:
1724 // Use GetInPlaceByHistory
1725 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1732 if (!CORBA::is_nil(aSubO)) {
1733 // add to parts list
1734 addToListOfGO( aSubO, aParts );
1736 // Publish the sub-shape
1737 SALOMEDS::SObject_var aSubSO;
1738 if (!CORBA::is_nil(theSObject)) {
1739 TCollection_AsciiString aSubName;
1743 aSubName += anArgName;
1744 aSubSO = aStudyBuilder->NewObject(theSObject);
1745 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1747 aSubO->SetColor(anArgO->GetColor());
1749 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1750 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1751 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1752 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1756 if (!CORBA::is_nil(anArgSO)) {
1757 // Restore published sub-shapes of the argument
1758 GEOM::ListOfGO_var aSubParts;
1759 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1760 // pass theObject, because only it has the history
1761 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1762 theObject, anArgs, theFindMethod, theAddPrefix);
1764 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1765 aSubO, anArgs, theFindMethod, theAddPrefix);
1766 // add to parts list
1767 addToListOfGO( aSubParts, aParts );
1770 else { // GetInPlace failed, try to build from published parts
1771 if (!CORBA::is_nil(anArgSO)) {
1772 SALOMEDS::SObject_var aSubSO;
1773 if (!CORBA::is_nil(theSObject))
1774 aSubSO = aStudyBuilder->NewObject(theSObject);
1776 // Restore published sub-shapes of the argument
1777 GEOM::ListOfGO_var aSubParts =
1778 RestoreGivenSubShapesOneLevel(theStudy, anArgSO, aSubSO,
1779 theObject, anArgs, theFindMethod, theAddPrefix);
1781 // add to parts list
1782 addToListOfGO( aSubParts, aParts );
1784 if (aSubParts->length() > 0) {
1785 // try to build an argument from a set of its sub-shapes,
1786 // that published and will be reconstructed
1787 if (aSubParts->length() > 1) {
1788 aSubO = aShapesOp->MakeCompound(aSubParts);
1789 // add to parts list
1790 addToListOfGO( aSubO, aParts );
1793 aSubO = aSubParts[0];
1795 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1796 // Publish the sub-shape
1797 TCollection_AsciiString aSubName;
1799 aSubName = "from_parts_of_";
1801 aSubName += anArgName;
1802 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
1804 aSubO->SetColor(anArgO->GetColor());
1806 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1807 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1808 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1809 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1813 else if (!CORBA::is_nil(aSubSO)) {
1814 // remove created aSubSO, because no parts have been found
1815 aStudyBuilder->RemoveObject(aSubSO);
1818 } // try to build from published parts
1819 anArgSO->UnRegister();
1821 } // process arguments
1823 std::set<std::string> anObjEntryMap;
1824 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1826 int nb = aParts->length();
1827 aResParts->length(nb);
1830 Handle(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
1831 Handle(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1832 GEOM::TPythonDump pd (aFunction, true);
1835 for ( ; i < nb; i++ )
1837 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1838 if (CORBA::is_nil(anObj))
1840 char* anEntry = anObj->GetEntry();
1841 if (anObjEntryMap.count(anEntry))
1842 continue; // already treated
1843 anObjEntryMap.insert(anEntry);
1844 aResParts[nbRes++] = anObj;
1845 // clear python dump of object
1846 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anEntry);
1847 Handle(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1848 if ( !anObjFun.IsNull() )
1849 anObjFun->SetDescription( "" );
1855 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1856 i = 0; nb = theArgs.length(); j = 0;
1857 for ( ; i < nb; i++ )
1859 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1860 if (CORBA::is_nil(anObj))
1862 Handle(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetStudyID(), anObj->GetEntry());
1868 pd <<"]" << ", " <<"GEOM.";
1869 switch (theFindMethod) {
1870 case GEOM::FSM_GetInPlace:
1871 pd << "FSM_GetInPlace"; break;
1872 case GEOM::FSM_MultiTransformed:
1873 pd << "FSM_MultiTransformed"; break;
1874 case GEOM::FSM_Transformed:
1875 pd << "FSM_Transformed"; break;
1876 case GEOM::FSM_GetSame:
1877 pd << "FSM_GetSame"; break;
1878 case GEOM::FSM_GetShapesOnShape:
1879 pd << "FSM_GetShapesOnShape"; break;
1880 case GEOM::FSM_GetInPlaceByHistory:
1882 pd << "FSM_GetInPlaceByHistory"; break;
1884 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1886 aResParts->length(nbRes);
1887 return aResParts._retn();
1890 //============================================================================
1891 // function : RestoreGivenSubShapesOneLevel
1892 // purpose : Private method
1893 //============================================================================
1894 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
1895 SALOMEDS::SObject_ptr theOldSO,
1896 SALOMEDS::SObject_ptr theNewSO,
1897 GEOM::GEOM_Object_ptr theNewO,
1898 std::set<std::string> theArgs,
1899 GEOM::find_shape_method theFindMethod,
1900 CORBA::Boolean theAddPrefix)
1903 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1904 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1905 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
1906 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1907 return aParts._retn();
1909 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1911 // Get interface, containing method, which we will use to reconstruct sub-shapes
1912 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1913 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1914 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId());
1916 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1917 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1919 // Reconstruct published sub-shapes
1920 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1923 for (it->Init(); it->More(); it->Next()) {
1926 aParts->length(aLen);
1928 for (it->Init(); it->More(); it->Next()) {
1929 SALOMEDS::SObject_var anOldSubSO = it->Value();
1931 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1933 SALOMEDS::GenericAttribute_var anAttr;
1934 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1935 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1936 GEOM::GEOM_Object_var anOldSubO =
1937 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1939 bool okToContinue = false;
1941 if (!CORBA::is_nil(anOldSubO)) {
1942 CORBA::String_var anEntry = anOldSubO->GetEntry();
1943 okToContinue = theArgs.count(anEntry.in());
1947 // Find a sub-shape of theNewO in place of anOldSubO
1948 GEOM::GEOM_Object_var aNewSubO;
1949 switch (theFindMethod) {
1950 case GEOM::FSM_GetInPlace:
1953 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1956 case GEOM::FSM_MultiTransformed:
1958 // Only for Multi-transformations
1959 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1960 if (!CORBA::is_nil(anArgOTrsf)) {
1961 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1962 Handle(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry);
1963 Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1964 anArgOTrsfFun->SetDescription("");
1965 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1969 case GEOM::FSM_Transformed:
1971 // transformation, cannot use GetInPlace, operate with indices
1972 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1973 if (anIDs->length() > 1) {
1975 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1976 if (!CORBA::is_nil(aNewSubO))
1977 aGroupOp->UnionIDs(aNewSubO, anIDs);
1981 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1985 case GEOM::FSM_GetSame:
1988 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1991 case GEOM::FSM_GetShapesOnShape:
1993 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1994 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1995 (short)GEOM::SOLID, GEOM::ST_ONIN);
1998 case GEOM::FSM_GetInPlaceByHistory:
2000 // Use GetInPlaceByHistory
2001 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2008 if (!CORBA::is_nil(aNewSubO)) {
2009 // add the part to the list
2010 aParts[i] = aNewSubO;
2012 // add to parts list
2013 addToListOfGO( aNewSubO, aNewParts );
2015 SALOMEDS::SObject_var aNewSubSO;
2016 if (!CORBA::is_nil(theNewSO)) {
2017 // Publish the sub-shape
2018 TCollection_AsciiString aSubName;
2022 aSubName += anArgName;
2023 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2024 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2026 aNewSubO->SetColor(anOldSubO->GetColor());
2028 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2029 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2030 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2031 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2034 // Restore published sub-shapes of the argument
2035 GEOM::ListOfGO_var aSubParts;
2036 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2037 // pass the main shape as Object, because only it has the history
2038 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2039 theNewO, theArgs, theFindMethod, theAddPrefix);
2041 aSubParts = RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2042 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2043 // add to parts list
2044 addToListOfGO( aSubParts, aNewParts );
2046 else { // GetInPlace failed, try to build from published parts
2047 SALOMEDS::SObject_var aNewSubSO;
2048 if (!CORBA::is_nil(theNewSO))
2049 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2051 // Restore published sub-shapes of the argument
2052 GEOM::ListOfGO_var aSubParts =
2053 RestoreGivenSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO,
2054 theNewO, theArgs, theFindMethod, theAddPrefix);
2055 // add to parts list
2056 addToListOfGO( aSubParts, aNewParts );
2058 if (aSubParts->length() > 0) {
2059 // try to build an object from a set of its sub-shapes,
2060 // that published and will be reconstructed
2061 if (aSubParts->length() > 1) {
2062 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2063 // add to parts list
2064 addToListOfGO( aNewSubO, aNewParts );
2067 aNewSubO = aSubParts[0];
2070 if (!CORBA::is_nil(aNewSubO)) {
2071 // add the part to the list
2072 aSubParts[i] = aNewSubO;
2075 // Publish the sub-shape
2076 if (!CORBA::is_nil(aNewSubSO)) {
2077 TCollection_AsciiString aSubName;
2079 aSubName = "from_parts_of_";
2081 aSubName += anArgName;
2082 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
2084 aNewSubO->SetColor(anOldSubO->GetColor());
2086 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2087 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2088 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2089 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2094 else if (!CORBA::is_nil(aNewSubSO)) {
2095 // remove created aSubSO, because no parts have been found
2096 aStudyBuilder->RemoveObject(aNewSubSO);
2098 } // try to build from published parts
2101 } // iterate on published sub-shapes
2104 // add to parts list
2105 addToListOfGO( aNewParts, aParts );
2106 return aParts._retn();
2109 //============================================================================
2110 // function : register()
2111 // purpose : register 'name' in 'name_service'
2112 //============================================================================
2113 void GEOM_Gen_i::register_name(char * name)
2115 GEOM::GEOM_Gen_var g = _this();
2116 name_service->Register(g, name);
2119 //============================================================================
2122 //============================================================================
2123 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
2125 _impl->Undo(theStudyID);
2128 //============================================================================
2131 //============================================================================
2132 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
2134 _impl->Redo(theStudyID);
2137 //============================================================================
2138 // function : GetIBasicOperations
2140 //============================================================================
2141 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
2142 throw ( SALOME::SALOME_Exception )
2144 Unexpect aCatch(SALOME_SalomeException);
2145 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2147 GEOM::GEOM_Gen_ptr engine = _this();
2149 //transfer reference on engine
2150 GEOM_IBasicOperations_i* aServant =
2151 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
2153 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2154 // activate the CORBA servant
2155 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2156 return operations._retn();
2159 //============================================================================
2160 // function : GetITransformOperations
2162 //============================================================================
2163 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
2164 throw ( SALOME::SALOME_Exception )
2166 Unexpect aCatch(SALOME_SalomeException);
2167 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2169 GEOM::GEOM_Gen_ptr engine = _this();
2171 GEOM_ITransformOperations_i* aServant =
2172 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
2174 // activate the CORBA servant
2175 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2176 return operations._retn();
2179 //============================================================================
2180 // function : GetI3DPrimOperations
2182 //============================================================================
2183 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
2184 throw ( SALOME::SALOME_Exception )
2186 Unexpect aCatch(SALOME_SalomeException);
2187 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2189 GEOM::GEOM_Gen_ptr engine = _this();
2191 GEOM_I3DPrimOperations_i* aServant =
2192 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
2193 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2195 // activate the CORBA servant
2196 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2197 return operations._retn();
2200 //============================================================================
2201 // function : GetIShapesOperations
2203 //============================================================================
2204 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
2205 throw ( SALOME::SALOME_Exception )
2207 Unexpect aCatch(SALOME_SalomeException);
2208 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2210 GEOM::GEOM_Gen_ptr engine = _this();
2212 GEOM_IShapesOperations_i* aServant =
2213 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
2215 // activate the CORBA servant
2216 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2217 return operations._retn();
2220 //============================================================================
2221 // function : GetIBlocksOperations
2223 //============================================================================
2224 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
2225 throw ( SALOME::SALOME_Exception )
2227 Unexpect aCatch(SALOME_SalomeException);
2228 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2230 GEOM::GEOM_Gen_ptr engine = _this();
2232 GEOM_IBlocksOperations_i* aServant =
2233 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
2235 // activate the CORBA servant
2236 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2237 return operations._retn();
2240 //============================================================================
2241 // function : GetIBooleanOperations
2243 //============================================================================
2244 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
2245 throw ( SALOME::SALOME_Exception )
2247 Unexpect aCatch(SALOME_SalomeException);
2248 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2250 GEOM::GEOM_Gen_ptr engine = _this();
2252 GEOM_IBooleanOperations_i* aServant =
2253 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
2255 // activate the CORBA servant
2256 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2257 return operations._retn();
2260 //============================================================================
2261 // function : GetICurvesOperations
2263 //============================================================================
2264 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
2265 throw ( SALOME::SALOME_Exception )
2267 Unexpect aCatch(SALOME_SalomeException);
2268 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2270 GEOM::GEOM_Gen_ptr engine = _this();
2272 GEOM_ICurvesOperations_i* aServant =
2273 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
2275 // activate the CORBA servant
2276 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2277 return operations._retn();
2280 //============================================================================
2281 // function : GetILocalOperations
2283 //============================================================================
2284 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
2285 throw ( SALOME::SALOME_Exception )
2287 Unexpect aCatch(SALOME_SalomeException);
2288 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2290 GEOM::GEOM_Gen_ptr engine = _this();
2292 GEOM_ILocalOperations_i* aServant =
2293 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
2295 // activate the CORBA servant
2296 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2297 return operations._retn();
2300 //============================================================================
2301 // function : GetIHealingOperations
2303 //============================================================================
2304 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
2305 throw ( SALOME::SALOME_Exception )
2307 Unexpect aCatch(SALOME_SalomeException);
2308 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2310 GEOM::GEOM_Gen_ptr engine = _this();
2312 GEOM_IHealingOperations_i* aServant =
2313 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
2315 // activate the CORBA servant
2316 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2317 return operations._retn();
2320 //============================================================================
2321 // function : GetIInsertOperations
2323 //============================================================================
2324 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
2325 throw ( SALOME::SALOME_Exception )
2327 Unexpect aCatch(SALOME_SalomeException);
2328 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2330 GEOM::GEOM_Gen_ptr engine = _this();
2332 GEOM_IInsertOperations_i* aServant =
2333 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
2335 // activate the CORBA servant
2336 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2337 return operations._retn();
2340 //============================================================================
2341 // function : GetIMeasureOperations
2343 //============================================================================
2344 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
2345 throw ( SALOME::SALOME_Exception )
2347 Unexpect aCatch(SALOME_SalomeException);
2348 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2350 GEOM::GEOM_Gen_ptr engine = _this();
2352 GEOM_IMeasureOperations_i* aServant =
2353 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
2355 // activate the CORBA servant
2356 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2357 return operations._retn();
2360 //============================================================================
2361 // function : GetIGroupOperations
2363 //============================================================================
2364 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
2365 throw ( SALOME::SALOME_Exception )
2367 Unexpect aCatch(SALOME_SalomeException);
2368 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2370 GEOM::GEOM_Gen_ptr engine = _this();
2372 GEOM_IGroupOperations_i* aServant =
2373 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
2375 // activate the CORBA servant
2376 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2377 return operations._retn();
2380 //============================================================================
2381 // function : GetIFieldOperations
2383 //============================================================================
2384 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations(CORBA::Long theStudyID)
2385 throw ( SALOME::SALOME_Exception )
2387 Unexpect aCatch(SALOME_SalomeException);
2388 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2390 GEOM::GEOM_Gen_ptr engine = _this();
2392 GEOM_IFieldOperations_i* aServant =
2393 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations(theStudyID));
2395 // activate the CORBA servant
2396 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2397 return operations._retn();
2400 //============================================================================
2401 // function : GetPluginOperations
2403 //============================================================================
2404 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(CORBA::Long theStudyID,
2405 const char* theLibName)
2406 throw ( SALOME::SALOME_Exception )
2408 std::string aPlatformLibName;
2410 aPlatformLibName = theLibName;
2411 aPlatformLibName += ".dll" ;
2413 aPlatformLibName = "lib";
2414 aPlatformLibName += theLibName;
2415 aPlatformLibName += ".so";
2418 Unexpect aCatch(SALOME_SalomeException);
2419 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2421 GEOM::GEOM_Gen_ptr engine = _this();
2423 GEOM_IOperations_i* aServant = 0;
2424 GEOM::GEOM_IOperations_var operations;
2427 // check, if corresponding operations are already created
2428 if (myOpCreatorMap.find(std::string(theLibName)) == myOpCreatorMap.end()) {
2429 // load plugin library
2430 LibHandle libHandle = LoadLib( aPlatformLibName.c_str()/*theLibName*/ );
2432 // report any error, if occured
2434 const char* anError = dlerror();
2435 throw(SALOME_Exception(anError));
2437 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2441 // get method, returning operations creator
2442 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2443 GetOperationsCreator procHandle =
2444 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2446 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2447 UnLoadLib(libHandle);
2450 // get operations creator
2451 GEOM_GenericOperationsCreator* aCreator = procHandle();
2453 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2456 // map operations creator to a plugin name
2457 myOpCreatorMap[std::string(theLibName)] = aCreator;
2460 // create a new operations object, store its ref. in engine
2461 aServant = myOpCreatorMap[std::string(theLibName)]->Create(_poa, theStudyID, engine, _impl);
2462 //??? aServant->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
2464 catch (SALOME_Exception& S_ex) {
2465 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2469 return operations._retn();
2471 // activate the CORBA servant
2472 operations = GEOM::GEOM_IOperations::_narrow( aServant->_this() );
2473 return operations._retn();
2476 //=============================================================================
2480 //=============================================================================
2481 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2482 const GEOM::ListOfLong& theIndices)
2484 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2485 return GEOM::GEOM_Object::_nil();
2486 CORBA::String_var entry = theMainShape->GetEntry();
2487 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast
2488 ( _impl->GetObject( theMainShape->GetStudyID(), entry ));
2489 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2491 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2492 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2494 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2495 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2497 TCollection_AsciiString anEntry;
2498 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2499 return GEOM::GEOM_Object::_narrow( GetObject(anObject->GetDocID(), anEntry.ToCString()));
2502 //=============================================================================
2506 //=============================================================================
2507 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2509 CORBA::String_var anEntry = theObject->GetEntry();
2510 Handle(GEOM_BaseObject) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry, false);
2511 if (!anObject.IsNull())
2512 _impl->RemoveObject(anObject);
2515 //=================================================================================
2516 // function : GetStringFromIOR()
2517 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2518 //=================================================================================
2519 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2521 return _orb->object_to_string(theObject);
2524 //=================================================================================
2525 // function : GetIORFromString()
2526 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2527 //=================================================================================
2528 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2529 GEOM::GEOM_Object_var aGeomObject;
2530 if(strcmp(stringIOR,"") != 0){
2531 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2532 if(!CORBA::is_nil(anObject))
2533 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2535 return aGeomObject._retn();
2538 //=================================================================================
2539 // function : GetObject()
2541 //=================================================================================
2542 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
2544 GEOM::GEOM_BaseObject_var obj;
2545 Handle(GEOM_BaseObject) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
2546 if (handle_object.IsNull()) return obj._retn();
2548 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2549 if (stringIOR.Length() > 1) {
2550 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2551 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2555 GEOM::GEOM_Gen_ptr engine = _this();
2556 //transfer the reference to GEOM_Object_i
2557 GEOM_BaseObject_i* servant = 0;
2558 switch( handle_object->GetType() ) {
2560 servant = new GEOM_Field_i (_poa, engine, Handle(GEOM_Field)::DownCast( handle_object ));
2563 case GEOM_FIELD_STEP: {
2564 Handle(GEOM_FieldStep) step = Handle(GEOM_FieldStep)::DownCast( handle_object );
2565 Handle(GEOM_Field) field = step->GetField();
2566 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2568 case GEOM::FDT_Bool:
2569 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2572 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2574 case GEOM::FDT_Double:
2575 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2578 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2583 servant = new GEOM_Object_i (_poa, engine, Handle(GEOM_Object)::DownCast( handle_object ));
2585 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2587 obj = servant->_this();
2588 CORBA::String_var objStr = _orb->object_to_string(obj);
2589 TCollection_AsciiString anAscii( (char *)objStr.in() );
2590 handle_object->SetIOR( anAscii );
2594 //=================================================================================
2595 // function : hasObjectInfo()
2596 // purpose : shows if module provides information for its objects
2597 //=================================================================================
2598 bool GEOM_Gen_i::hasObjectInfo()
2603 //=================================================================================
2604 // function : getObjectInfo()
2605 // purpose : returns an information for a given object by its entry
2606 //=================================================================================
2607 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
2609 GEOM::GEOM_Object_var aGeomObject;
2611 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2612 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2613 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2614 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
2615 SALOMEDS::SObject_var aResultSObj;
2616 if (aSObj->ReferencedObject(aResultSObj))
2617 aSObj = aResultSObj;
2619 SALOMEDS::GenericAttribute_var anAttr;
2620 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2621 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2622 CORBA::String_var aVal = anIOR->Value();
2623 anIOR->UnRegister();
2624 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
2625 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2627 if (!aSObj->_is_nil() )
2628 aSObj->UnRegister();
2630 const char* aTypeInfo = "Object";
2631 if ( !aGeomObject->_is_nil() ) {
2632 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2633 GEOM::ListOfLong_var anInts;
2634 GEOM::ListOfDouble_var aDbls;
2636 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
2637 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2639 if ( anOp->IsDone() ) {
2641 case GEOM::GEOM_IKindOfShape::COMPOUND:
2642 aTypeInfo = "Compound";
2644 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2645 aTypeInfo = "CompSolid";
2647 case GEOM::GEOM_IKindOfShape::SHELL:
2648 aTypeInfo = "Shell";
2650 case GEOM::GEOM_IKindOfShape::WIRE:
2651 if ( anInts[0] == 1 )
2652 aTypeInfo = "Closed Wire";
2653 else if ( anInts[0] == 2 )
2654 aTypeInfo = "Opened Wire";
2659 case GEOM::GEOM_IKindOfShape::SPHERE:
2660 aTypeInfo = "Sphere";
2662 case GEOM::GEOM_IKindOfShape::CYLINDER:
2663 aTypeInfo = "Cylinder";
2665 case GEOM::GEOM_IKindOfShape::BOX:
2666 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2669 case GEOM::GEOM_IKindOfShape::TORUS:
2670 aTypeInfo = "Torus";
2672 case GEOM::GEOM_IKindOfShape::CONE:
2675 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2676 aTypeInfo = "Polyhedron";
2678 case GEOM::GEOM_IKindOfShape::SOLID:
2679 aTypeInfo = "Solid";
2682 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2683 aTypeInfo = "Spherical Face";
2685 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2686 aTypeInfo = "Cylindrical Face";
2688 case GEOM::GEOM_IKindOfShape::TORUS2D:
2689 aTypeInfo = "Toroidal Face";
2691 case GEOM::GEOM_IKindOfShape::CONE2D:
2692 aTypeInfo = "Conical Face";
2694 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2697 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2698 aTypeInfo = "Elliptical Face";
2700 case GEOM::GEOM_IKindOfShape::POLYGON:
2701 aTypeInfo = "Polygon";
2703 case GEOM::GEOM_IKindOfShape::PLANE:
2704 aTypeInfo = "Plane";
2706 case GEOM::GEOM_IKindOfShape::PLANAR:
2707 aTypeInfo = "Planar Face";
2709 case GEOM::GEOM_IKindOfShape::FACE:
2713 case GEOM::GEOM_IKindOfShape::CIRCLE:
2714 aTypeInfo = "Circle";
2716 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2717 aTypeInfo = "Arc Circle";
2719 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2720 aTypeInfo = "Ellipse";
2722 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2723 aTypeInfo = "Arc Ellipse";
2725 case GEOM::GEOM_IKindOfShape::LINE:
2728 case GEOM::GEOM_IKindOfShape::SEGMENT:
2729 aTypeInfo = "Segment";
2731 case GEOM::GEOM_IKindOfShape::EDGE:
2734 case GEOM::GEOM_IKindOfShape::VERTEX:
2735 aTypeInfo = "Vertex";
2743 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
2744 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
2746 char* ret = CORBA::string_dup(anInfo);
2751 // Version information
2752 char* GEOM_Gen_i::getVersion()
2754 #if GEOM_DEVELOPMENT
2755 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2757 return CORBA::string_dup(GEOM_VERSION_STR);
2761 //=================================================================================
2762 // function : CreateFolder()
2763 // purpose : Creates and returns a new folder object
2764 //=================================================================================
2765 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2766 SALOMEDS::SObject_ptr theFather)
2768 SALOMEDS::SObject_var aFolderSO;
2770 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2772 SALOMEDS::GenericAttribute_var anAttr;
2773 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2774 // not a GEOM component object was selected
2775 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2776 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2777 if( aLocalID->Value() != 999 ) {
2778 // not a Folder object was selected
2779 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2780 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2781 // another GEOM object was selected, so get GEOM component as father object
2782 theFather = theFather->GetFatherComponent();
2784 aLocalID->UnRegister();
2787 SALOMEDS::Study_var aStudy = theFather->GetStudy();
2788 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2789 aFolderSO = aStudyBuilder->NewObject( theFather );
2791 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2792 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2793 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2794 aLocalID->UnRegister();
2796 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2797 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2798 aName->SetValue( theName );
2799 aName->UnRegister();
2801 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2802 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2803 aPixMap->SetPixMap("ICON_FOLDER");
2804 aPixMap->UnRegister();
2806 // add object to the use case tree
2807 // (to support tree representation customization and drag-n-drop)
2808 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2809 useCaseBuilder->AppendTo( theFather, aFolderSO );
2811 return aFolderSO._retn();
2814 //=================================================================================
2815 // function : MoveToFolder()
2816 // purpose : Moves GEOM object to the specified folder
2817 //=================================================================================
2818 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2819 SALOMEDS::SObject_ptr theFolder) {
2820 GEOM::object_list_var objects = new GEOM::object_list();
2821 objects->length( 1 );
2822 SALOMEDS::SObject_var aSO = theFolder->GetStudy()->FindObjectID( theObject->GetStudyEntry() );
2824 Move( objects, theFolder, -1 );
2827 //=================================================================================
2828 // function : MoveListToFolder()
2829 // purpose : Moves list of GEOM objects to the specified folder
2830 //=================================================================================
2831 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2832 SALOMEDS::SObject_ptr theFolder) {
2833 int aLen = theListOfGO.length();
2834 GEOM::object_list_var objects = new GEOM::object_list();
2835 objects->length( aLen );
2836 GEOM::GEOM_Object_var aGO;
2837 SALOMEDS::SObject_var aSO;
2838 for (int i = 0; i < aLen; i++) {
2839 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2840 aSO = theFolder->GetStudy()->FindObjectID( aGO->GetStudyEntry() );
2843 if ( objects->length() > 0 )
2844 Move( objects, theFolder, -1 );
2847 //=================================================================================
2848 // function : Move()
2849 // purpose : Moves objects to the specified position.
2850 // Is used in the drag-n-drop functionality.
2851 //=================================================================================
2852 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2853 SALOMEDS::SObject_ptr where,
2856 if ( CORBA::is_nil( where ) ) return;
2858 SALOMEDS::Study_var study = where->GetStudy();
2859 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2860 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2861 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2862 std::string dataType = father->ComponentDataType();
2863 if ( dataType != "GEOM" ) return; // not a GEOM component
2865 SALOMEDS::SObject_var objAfter;
2866 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2867 // insert at given row -> find insertion position
2868 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2870 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2871 if ( i == row && useCaseIt->More() ) {
2872 objAfter = useCaseIt->Value();
2876 for ( int i = 0; i < what.length(); i++ ) {
2877 SALOMEDS::SObject_var sobj = what[i];
2878 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2879 // insert the object to the use case tree
2880 if ( !CORBA::is_nil( objAfter ) )
2881 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2883 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2887 //=================================================================================
2888 // function : importData
2889 // purpose : imports geometrical data file into the GEOM internal data structure
2890 //=================================================================================
2891 Engines::ListOfIdentifiers* GEOM_Gen_i::importData(
2892 CORBA::Long studyId, Engines::DataContainer_ptr data, const Engines::ListOfOptions& options)
2894 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
2895 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2896 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2898 Engines::ListOfIdentifiers_var aResult = new Engines::ListOfIdentifiers;
2899 GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
2900 if (aInsOp->_is_nil()) {
2901 MESSAGE("No insert operations!");
2902 return aResult._retn();
2905 // Get a temporary directory to store a file
2906 std::string aTmpDir = SALOMEDS_Tool::GetTmpDir();
2907 std::string aFileName("file");
2908 if (aFileName.rfind("/") != std::string::npos) { // remove folders from the name
2909 aFileName = aFileName.substr(aFileName.rfind("/") + 1);
2912 std::string anExtension(data->extension());
2913 aFileName += "." + anExtension;
2914 // convert extension to upper case
2915 std::transform(anExtension.begin(), anExtension.end(), anExtension.begin(), ::toupper);
2916 std::string aFullPath = aTmpDir + aFileName;
2918 Engines::TMPFile* aFileStream = data->get();
2919 const char *aBuffer = (const char*)aFileStream->NP_data();
2921 std::ofstream aFile(aFullPath.c_str(), std::ios::binary);
2923 std::ofstream aFile(aFullPath.c_str());
2925 aFile.write(aBuffer, aFileStream->length());
2928 GEOM::GEOM_Object_var aShapeObj;
2929 GEOM::ListOfGO_var aSubShape = new GEOM::ListOfGO;
2930 GEOM::ListOfGO_var aGroups = new GEOM::ListOfGO;
2931 GEOM::ListOfFields_var aFields = new GEOM::ListOfFields;
2933 CORBA::Boolean isResultOK = aInsOp->ImportXAO(aFullPath.c_str(), aShapeObj.out(), aSubShape.out(), aGroups.out(), aFields.out());
2935 if ( isResultOK && !aShapeObj->_is_nil() && aInsOp->IsDone() ) {
2936 SALOMEDS::SObject_var aSO = PublishInStudy(aStudy, SALOMEDS::SObject::_nil(), aShapeObj, aShapeObj->GetName());
2937 aResult->length(aGroups->length() + 1);
2938 aResult[0] = aSO->GetID(); // unioque identifer of the object in GEOM is entry of SObject
2939 //Iteration for objects of the group.
2940 for (int i = 0; i < aGroups->length(); i++) {
2941 SALOMEDS::SObject_var aSOChild = AddInStudy(aStudy, aGroups[i], aGroups[i]->GetName(), aShapeObj);
2942 aResult[i+1] = aSOChild->GetID();
2946 if (aShapeObj->_is_nil())
2947 MESSAGE("Result of the import operation is incorrect for file "<<aFullPath.c_str());
2948 if (!aInsOp->IsDone())
2949 MESSAGE("Import operation is not done for file "<<aFullPath.c_str());
2951 MESSAGE("ImportXAO operation is failed for file "<<aFullPath.c_str());
2952 return aResult._retn();
2955 // remove temporary file and directory
2956 SALOMEDS::ListOfFileNames aTmpFiles;
2957 aTmpFiles.length(1);
2958 aTmpFiles[0] = aFileName.c_str();
2959 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aTmpFiles, true);
2961 _impl->DocumentModified(studyId, false);
2962 return aResult._retn();
2965 //=================================================================================
2966 // function : getModifiedData
2967 // purpose : exports all geometry of this GEOM module into one BRep file
2968 //=================================================================================
2969 Engines::ListOfData* GEOM_Gen_i::getModifiedData(CORBA::Long studyId)
2971 Engines::ListOfData_var aResult = new Engines::ListOfData;
2973 if (!_impl->DocumentModified(studyId)) {
2974 MESSAGE("Document is not modified")
2975 return aResult._retn();
2978 CORBA::Object_var aSMObject = name_service->Resolve("/myStudyManager");
2979 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
2980 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
2981 SALOMEDS::SComponent_var aComponent = aStudy->FindComponent("GEOM");
2982 if (CORBA::is_nil(aComponent))
2983 return aResult._retn();
2984 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(aComponent); // check only published shapes
2986 GEOM::GEOM_Object_var shapeObj;
2987 GEOM::ListOfGO_var groups = new GEOM::ListOfGO;
2988 GEOM::ListOfFields_var fields = new GEOM::ListOfFields;
2989 std::string anAuthorName = "SIMAN Author";
2991 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(aStudy->StudyId());
2992 GEOM::GEOM_IInsertOperations_var aInsOp = GetIInsertOperations(aStudy->StudyId());
2994 int aSeqLength = 0; // the sequence length
2995 for(; anIter->More(); anIter->Next()) {
2996 SALOMEDS::SObject_var aSO = anIter->Value();
2997 SALOMEDS::SObject_var aRefSO;
2998 // export only not referenced objects, or referenced outside of GEOM
2999 if (!aSO->ReferencedObject(aRefSO) || aRefSO->GetFatherComponent()->GetID() != aComponent->GetID()) {
3000 CORBA::Object_var anObj = aSO->GetObject();
3001 if (!CORBA::is_nil(anObj)) {
3002 GEOM::GEOM_Object_var aCORBAMainShape = GEOM::GEOM_Object::_narrow(anObj);
3003 if(!aCORBAMainShape->_is_nil()) {
3004 CORBA::String_var entry = aCORBAMainShape->GetEntry();
3005 Handle(GEOM_Object) aMainShape = Handle(GEOM_Object)::DownCast(_impl->GetObject(studyId, entry));
3007 GEOM::shape_type aCORBAShapeType = aCORBAMainShape->GetShapeType();
3008 if (!aMainShape.IsNull() && !(aCORBAShapeType == GEOM::VERTEX) && !(aCORBAShapeType == GEOM::EDGE)) {
3010 shapeObj = aCORBAMainShape;
3011 if (aShapesOp->_is_nil()) {
3012 MESSAGE("No shapes operations!");
3013 return aResult._retn();
3015 groups = aShapesOp->GetExistingSubObjects(aCORBAMainShape, true);
3023 if (aInsOp->_is_nil()) {
3024 MESSAGE("No insert operations!");
3025 return aResult._retn();
3028 if (aSeqLength > 0) { // Shape is correct, write it to the temporary file
3030 std::string aFullXaoPath = Kernel_Utils::GetTmpFileName() + ".xao";
3031 CORBA::Boolean isResultOK = aInsOp->ExportXAO(shapeObj.in(), groups.in(), fields.in(), anAuthorName.c_str(), aFullXaoPath.c_str());
3034 Engines::DataContainer_var aData = (new Engines_DataContainer_i(
3035 aFullXaoPath.c_str(), "", "", true))->_this();
3038 MESSAGE("No shapes to export");
3041 return aResult._retn();
3044 //=====================================================================================
3046 //=====================================================================================
3051 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
3055 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
3056 PortableServer::POA_ptr poa,
3057 PortableServer::ObjectId* contId,
3058 const char* instanceName,
3059 const char* interfaceName)
3061 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
3062 return myGEOM_Gen_i->getId();