1 // Copyright (C) 2007-2020 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.hxx"
40 #include "GEOM_Function.hxx"
41 #include "GEOM_ISubShape.hxx"
42 #include "GEOM_PythonDump.hxx"
43 #include "GEOMImpl_Types.hxx"
44 #include "GEOMImpl_CopyDriver.hxx"
45 #include "GEOMImpl_IInsertOperations.hxx"
46 #include "GEOM_wrap.hxx"
47 #include "GEOMUtils_XmlHandler.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>
62 #include <TDataStd_ChildNodeIterator.hxx>
63 #include <TDocStd_Owner.hxx>
64 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
66 #include <SALOMEDS_Tool.hxx>
67 #include <SALOMEDS_wrap.hxx>
68 #include <Basics_DirUtils.hxx>
69 #include <Basics_Utils.hxx>
82 #define LibHandle HMODULE
83 #define LoadLib( name ) LoadLibrary( name )
84 #define GetProc GetProcAddress
85 #define UnLoadLib( handle ) FreeLibrary( handle );
87 #define LibHandle void*
88 #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
90 #define UnLoadLib( handle ) dlclose( handle );
93 //============================================================================
94 // function : GEOM_Gen_i()
95 // purpose : constructor to be called for servant creation.
96 //============================================================================
97 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
98 PortableServer::POA_ptr poa,
99 PortableServer::ObjectId* contId,
100 const char* instanceName,
101 const char* interfaceName) :
102 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
105 _id = _poa->activate_object(_thisObj);
106 name_service = new SALOME_NamingService(_orb);
108 _impl = new ::GEOMImpl_Gen;
110 //PAL10867: disable signals catching with "noexcepthandler" option
111 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
112 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
114 //work around PAL12004, PAL12628
115 //OSD::SetSignal( true );
116 bool raiseFPE = false;
117 #if defined(_DEBUG_) | defined(_DEBUG) //the Last for WIN32 default settings
118 char* envEnableFPE = getenv("ENABLE_FPE");
119 if (envEnableFPE && atoi(envEnableFPE))
122 OSD::SetSignal( raiseFPE );
125 GEOMUtils::PluginInfo plugins = GEOMUtils::ReadPluginInfo();
126 GEOMUtils::PluginInfo::const_iterator it;
127 for (it = plugins.begin(); it != plugins.end(); ++it)
130 LoadPlugin((*it).serverLib);
133 MESSAGE("Warning: can't load plugin library " << (*it).serverLib);
138 //============================================================================
139 // function : ~GEOM_Gen_i()
140 // purpose : destructor
141 //============================================================================
142 GEOM_Gen_i::~GEOM_Gen_i() {
145 std::map<std::string, GEOM_GenericOperationsCreator*>::const_iterator it;
146 for ( it = myOpCreatorMap.begin(); it != myOpCreatorMap.end(); ++it)
151 //============================================================================
152 // function : IORToLocalPersistentID()
154 //============================================================================
155 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
156 const char* IORString,
157 CORBA::Boolean isMultiFile,
158 CORBA::Boolean isASCII)
160 GEOM::GEOM_BaseObject_var anObject =
161 GEOM::GEOM_BaseObject::_narrow(_orb->string_to_object(IORString));
162 if (!CORBA::is_nil(anObject)) {
163 return anObject->GetEntry();
169 //============================================================================
170 // function : LocalPersistentIDToIOR()
171 // purpose : Create/Load CORBA object from a persistent ref (an entry)
172 // : Used when a study is loaded
173 // : The IOR (IORName) of object created is returned
174 //============================================================================
175 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
176 const char* aLocalPersistentID,
177 CORBA::Boolean isMultiFile,
178 CORBA::Boolean isASCII)
180 Handle(::GEOM_BaseObject) anObject =
181 _impl->GetObject(aLocalPersistentID);
182 if ( !anObject.IsNull() )
184 TCollection_AsciiString anEntry;
185 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
186 GEOM::GEOM_BaseObject_var obj = GetObject(anEntry.ToCString());
188 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
189 return CORBA::string_dup(aPersRefString);
193 return CORBA::string_dup("");
197 //============================================================================
198 // function : CanPublishInStudy
200 //============================================================================
201 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
203 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
204 return !(anObject->_is_nil());
208 //============================================================================
209 // function : PublishInStudy
211 //============================================================================
212 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
213 CORBA::Object_ptr theObject,
215 throw (SALOME::SALOME_Exception)
217 Unexpect aCatch(SALOME_SalomeException);
218 SALOMEDS::SObject_var aResultSO;
219 SALOMEDS::Study_var aStudy = getStudyServant();
220 if(CORBA::is_nil(theObject) || aStudy->_is_nil()) return aResultSO;
221 GEOM::GEOM_BaseObject_var aBaseObj = GEOM::GEOM_BaseObject::_narrow(theObject);
222 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
223 if(aBaseObj->_is_nil()) return aResultSO;
225 SALOMEDS::GenericAttribute_var anAttr;
226 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
227 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
229 SALOMEDS::SComponent_var aFather = findOrCreateComponent();
230 if (aFather->_is_nil()) return aResultSO;
232 if (CORBA::is_nil(theSObject)) {
233 aResultSO = aStudyBuilder->NewObject(aFather);
235 if (!theSObject->ReferencedObject(aResultSO))
236 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
237 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
239 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
240 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
242 TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
243 CORBA::Long mytype=aBaseObj->GetType();
245 // BEGIN: try to find existed name for current shape
246 if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
248 // receive current TopoDS shape
249 CORBA::String_var entry = aShape->GetEntry();
250 Handle(::GEOM_Object) aGShape = Handle(::GEOM_Object)::DownCast
251 ( _impl->GetObject( entry ));
252 TopoDS_Shape TopoSh = aGShape->GetValue();
253 // find label of main shape
254 GEOM::GEOM_Object_var aMainSh = aShape;
255 while( !aMainSh->IsMainShape() ) {
256 aMainSh = aMainSh->GetMainShape();
258 entry = aMainSh->GetEntry();
259 Handle(::GEOM_BaseObject) anObj = _impl->GetObject( entry );
260 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
262 // check all named shapes using iterator
263 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
265 for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
266 Handle(TNaming_NamedShape) anAttr =
267 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
268 if (anAttr.IsNull()) continue;
269 TopoDS_Shape S = anAttr->Get();
270 if (S.IsEqual(TopoSh)) {
271 TDF_Label L = anAttr->Label();
272 Handle(TDataStd_Name) aName;
273 if (L.FindAttribute(TDataStd_Name::GetID(), aName))
274 anObjectName = aName->Get();
278 // END: try to find existed name for current shape
280 if ( mytype == GEOM_GROUP ) {
281 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations();
282 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
284 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
285 aNamePrefix = "Group_Of_Vertices_";
288 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
289 aNamePrefix = "Group_Of_Edges_";
292 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
293 aNamePrefix = "Group_Of_Faces_";
296 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
297 aNamePrefix = "Group_Of_Solids_";
300 aNamePrefix = "Group_";
302 } else if ( mytype == GEOM_MARKER ) {
303 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
304 aNamePrefix = "LocalCS_";
305 } else if ( mytype >= USER_TYPE_EX ) {
307 sprintf( buf, "%d", aBaseObj->GetType() );
308 GEOM::CreationInformationSeq_var infoSeq = aBaseObj->GetCreationInformation();
310 for ( size_t j = 0; j < infoSeq->length(); ++j )
311 for ( size_t i = 0; i < infoSeq[j].params.length(); ++i ) {
312 std::string param_name = infoSeq[j].params[i].name.in();
313 std::string param_value = infoSeq[j].params[i].value.in();
314 if( param_name == PLUGIN_NAME) {
319 if(plgId.length() > 0 ) {
322 plgId +="ICON_OBJBROWSER_";
324 aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
325 } else if ( mytype > USER_TYPE ) {
327 sprintf( buf, "%d", aBaseObj->GetType() );
328 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
329 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
330 aNamePrefix = "Advanced_";
331 } else if ( mytype == GEOM_FIELD ) {
332 aNamePrefix = "Field_";
333 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
334 if ( !aField->_is_nil() )
335 switch( aField->GetDimension() ) {
337 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
339 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
341 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
343 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
345 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
347 } else if ( mytype == GEOM_FIELD_STEP ) {
348 aNamePrefix = "Step_";
349 } else if ( !aShape->_is_nil() ) {
350 GEOM::shape_type myshapetype=aShape->GetShapeType();
351 if ( myshapetype == GEOM::COMPOUND ) {
352 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
353 aNamePrefix = "Compound_";
354 } else if ( myshapetype == GEOM::COMPSOLID ) {
355 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
356 aNamePrefix = "Compsolid_";
357 } else if ( myshapetype == GEOM::SOLID ) {
358 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
359 aNamePrefix = "Solid_";
360 } else if ( myshapetype == GEOM::SHELL ) {
361 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
362 aNamePrefix = "Shell_";
363 } else if ( myshapetype == GEOM::FACE ) {
364 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
365 aNamePrefix = "Face_";
366 } else if ( myshapetype == GEOM::WIRE ) {
367 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
368 aNamePrefix = "Wire_";
369 } else if ( myshapetype == GEOM::EDGE ) {
370 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
371 aNamePrefix = "Edge_";
372 } else if ( myshapetype == GEOM::VERTEX ) {
373 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
374 aNamePrefix = "Vertex_";
377 if ( anObjectName.IsEmpty() )
379 //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
380 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
382 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
383 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
384 // of objects in the study, but compute a number of objects with the same prefix
385 // and build a new name as Prefix_N+1
386 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
387 int i = 0; // (WITH EMPTY NEW NAME)
388 SALOMEDS::SObject_var obj;
390 anObjectName = aNamePrefix + TCollection_AsciiString(++i);
391 obj = aStudy->FindObject( anObjectName.ToCString() );
393 while ( !obj->_is_nil() );
395 else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
396 anObjectName = theName;
400 //Set the study entry as a name of the published GEOM_Object
401 CORBA::String_var anID = aResultSO->GetID();
402 aBaseObj->SetStudyEntry(anID.in());
404 //Set a name of the added shape
405 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
407 //Set NoteBook variables used in the object creation
408 TCollection_AsciiString aVars;
409 CORBA::String_var aString=aBaseObj->GetParameters();
410 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aString);
411 for(int i = 0, n = aSections->length(); i < n; i++) {
412 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
413 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
414 if(aStudy->IsVariable(aListOfVars[j].in()))
415 aVars += aListOfVars[j].in();
422 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
424 aFather->UnRegister();
426 //Set a name of the GEOM object
427 aBaseObj->SetName(anObjectName.ToCString());
429 // add object to the use case tree
430 // (to support tree representation customization and drag-n-drop)
431 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
433 return aResultSO._retn();
436 //============================================================================
437 // function : CreateAndPublishGroup
438 // purpose : auxiliary for PublishNamedShapesInStudy
439 //============================================================================
440 void GEOM_Gen_i::CreateAndPublishGroup(GEOM::GEOM_Object_var theMainShape,
441 const TopTools_IndexedMapOfShape& anIndices,
442 const TopTools_SequenceOfShape& SeqS,
443 const TColStd_SequenceOfAsciiString& SeqN,
444 const Standard_CString& GrName,
445 GEOM::ListOfGO_var aResList)
447 CORBA::String_var entry = theMainShape->GetEntry();
448 //Handle(::GEOM_Object) aMainShape = _impl->GetObject(entry);
449 Handle(TColStd_HArray1OfInteger) anArray;
450 if(SeqS.Length()>0) {
452 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations();
453 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
454 AddInStudy(GrObj, GrName, theMainShape._retn());
455 //CORBA::String_var GrEntry = GrObj->GetEntry();
456 //Handle(::GEOM_Object) HGrObj = _impl->GetObject(GrEntry);
458 //Handle(::GEOM_Object) anObj;
459 for(int i=1; i<=SeqS.Length(); i++) {
460 TopoDS_Shape aValue = SeqS.Value(i);
461 //anArray = new TColStd_HArray1OfInteger(1,1);
462 Standard_Integer anIndex = anIndices.FindIndex(aValue);
463 //anArray->SetValue(1, anIndex);
464 GOp->AddObject(GrObj,anIndex);
465 //anObj = GEOM_Engine::GetEngine()->AddObject(GEOM_SUBSHAPE);
466 //if (anObj.IsNull()) continue;
467 //Handle(::GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
468 //if (aFunction.IsNull()) continue;
469 //GEOM_ISubShape aSSI(aFunction);
470 //aSSI.SetMainShape(aMainShape->GetLastFunction());
471 //aSSI.SetIndices(anArray);
472 //aFunction->SetValue(aValue);
473 //GOp->UnionIDs(GrObj, anIndex);
474 //SALOMEDS::SObject_var aResultSO;
475 //TCollection_AsciiString anEntry;
476 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
477 //GEOM::GEOM_Object_var aGObj = GetObject(anEntry.ToCString());
478 //AddInStudy(aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
484 //============================================================================
485 // function : PublishNamedShapesInStudy
487 //============================================================================
488 GEOM::ListOfGO* GEOM_Gen_i::
489 PublishNamedShapesInStudy(//SALOMEDS::SObject_ptr theSObject,
490 CORBA::Object_ptr theObject)
492 //Unexpect aCatch(SALOME_SalomeException);
493 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
495 //CORBA::Object_var theObject = theSObject->GetObject();
496 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
497 if(theMainShape->_is_nil()) return aResList._retn();
499 CORBA::String_var entry = theMainShape->GetEntry();
500 Handle(::GEOM_Object) aMainShape = Handle(::GEOM_Object)::DownCast
501 ( _impl->GetObject( entry ));
502 if (aMainShape.IsNull()) return aResList._retn();
503 TopoDS_Shape MainSh = aMainShape->GetValue();
505 TDF_Label aMainLbl = aMainShape->GetEntry();
506 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
507 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
508 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
509 for(; anIt.More(); anIt.Next()) {
510 Handle(TNaming_NamedShape) anAttr =
511 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
512 if(anAttr.IsNull()) continue;
513 TopoDS_Shape S = anAttr->Get();
514 TDF_Label L = anAttr->Label();
515 //if(S.IsEqual(MainSh)) continue;
516 Handle(TDataStd_Name) aName;
517 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
518 TCollection_ExtendedString EName = aName->Get();
519 if(S.ShapeType()==TopAbs_SOLID) {
521 SolidSeqN.Append(aName->Get());
523 else if(S.ShapeType()==TopAbs_FACE) {
525 FaceSeqN.Append(aName->Get());
527 else if(S.ShapeType()==TopAbs_EDGE) {
529 EdgeSeqN.Append(aName->Get());
531 else if(S.ShapeType()==TopAbs_VERTEX) {
533 VertSeqN.Append(aName->Get());
538 TopTools_IndexedMapOfShape anIndices;
539 TopExp::MapShapes(MainSh, anIndices);
541 CreateAndPublishGroup(theMainShape, anIndices, SolidSeqS, SolidSeqN,
542 "Group_Of_Named_Solids", aResList);
544 CreateAndPublishGroup(theMainShape, anIndices, FaceSeqS, FaceSeqN,
545 "Group_Of_Named_Faces", aResList);
547 CreateAndPublishGroup(theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
548 "Group_Of_Named_Edges", aResList);
550 CreateAndPublishGroup(theMainShape, anIndices, VertSeqS, VertSeqN,
551 "Group_Of_Named_Vertices", aResList);
553 return aResList._retn();
557 //============================================================================
559 // purpose : save OCAF/Geom document
560 //============================================================================
561 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
564 SALOMEDS::TMPFile_var aStreamFile;
565 // Get a temporary directory to store a file
566 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
568 // OCCT BUG: cannot save a document (in current folder)
569 // if directory name is empty
570 if (aTmpDir.size() == 0) {
578 // Create a list to store names of created files
579 SALOMEDS_Tool::ListOfFiles aSeq;
581 // Prepare a file name to open
582 TCollection_AsciiString aNameWithExt("");
584 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(
585 Kernel_Utils::encode(getStudyServant()->URL())).c_str()));
586 aNameWithExt += TCollection_AsciiString("_GEOM.cbf");
587 aSeq.push_back(CORBA::string_dup(aNameWithExt.ToCString()));
588 // Build a full file name of temporary file
589 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
590 // Save GEOM component in this file
591 if (_impl->Save((char*) aFullName.ToCString())) {
592 // Convert a file to the byte stream
593 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq, isMultiFile);
594 // Remove the created file and tmp directory
595 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
597 // Return the created byte stream
598 return aStreamFile._retn();
602 //============================================================================
603 // function : SaveASCII()
605 //============================================================================
606 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
609 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
610 return aStreamFile._retn();
614 //============================================================================
617 //============================================================================
618 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
619 const SALOMEDS::TMPFile& theStream,
623 if (theStream.length() <= 9) {
624 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
628 // Get a temporary directory for a file
629 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
631 // OCCT BUG: cannot load a document (from current folder)
632 // if directory name is empty
633 if (aTmpDir.size() == 0) {
641 // Conver the byte stream theStream to a file and place it in tmp directory
642 SALOMEDS_Tool::ListOfFiles aSeq =
643 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
645 // Prepare a file name to open
646 TCollection_AsciiString aNameWithExt("");
647 SALOMEDS::Study_var study = getStudyServant();
649 // Get the file name.
651 int aLength = aSeq.size();
652 const char *aGeomSgd = "_GEOM.sgd";
653 const char *aGeomcbf = "_GEOM.cbf";
655 for(i = 0; i < aLength; i++) {
656 std::string aName(aSeq[i]);
658 if (aName.rfind(aGeomSgd) != std::string::npos ||
659 aName.rfind(aGeomcbf) != std::string::npos) {
660 aNameWithExt = aName.c_str();
665 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
668 if (!_impl->Load((char*) aFullName.ToCString())) return false;
670 // Remove the created file and tmp directory
671 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
673 // creation of tree nodes for all data objects in the study
674 // to support tree representation customization and drag-n-drop:
675 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
676 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
677 useCaseBuilder->SetRootCurrent();
678 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
681 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
682 for ( it->InitEx(true); it->More(); it->Next() ) {
683 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
684 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
692 //============================================================================
693 // function : LoadASCII()
695 //============================================================================
696 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
697 const SALOMEDS::TMPFile& theStream,
700 return Load(theComponent, theStream, theURL, isMultiFile);
704 //============================================================================
705 // function : Close()
707 //============================================================================
708 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
713 //============================================================================
714 // function : CanCopy()
716 //============================================================================
717 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
718 // Try to retrieve known by Geometry component GEOM_Object by given IOR
719 SALOMEDS::GenericAttribute_var anAttr;
720 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
722 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
724 CORBA::String_var aString=anIOR->Value();
726 CORBA::Object_var anObj = _orb->string_to_object(aString);
727 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
728 // If the object is null one it can't be copied: return false
729 if (anObject->_is_nil()) return false;
733 //============================================================================
734 // function : CopyFrom()
736 //============================================================================
737 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
739 // Declare a sequence of the byte to store the copied object
740 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
742 // Try to get GEOM_Object object by given SObject
743 SALOMEDS::GenericAttribute_var anAttr;
744 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
745 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
746 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
747 if (anObject->_is_nil()) return aStreamFile._retn();
749 aStreamFile = anObject->GetShapeStream();
751 // Assign an ID the type of GEOM_Object
752 theObjectID = anObject->GetType();
754 // Return created TMPFile
755 return aStreamFile._retn();
758 //============================================================================
759 // function : CanPaste()
761 //============================================================================
762 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
763 // The Geometry component can paste only objects copied by Geometry component
764 // and with the object type = 1
765 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
769 //============================================================================
770 // function : PasteInto()
772 //============================================================================
773 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
774 CORBA::Long theObjectID,
775 SALOMEDS::SObject_ptr theObject) {
776 // Find the current Study and StudyBuilder
777 SALOMEDS::Study_var aStudy = getStudyServant();
778 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
779 SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
780 SALOMEDS::SObject_var aNewSO;
781 // Retrieve a TopoDS_Shape from byte stream
782 TopoDS_Shape aTopology;
783 std::istringstream aStreamedBrep((char*) &theStream[0]);
784 BRep_Builder aBuilder;
786 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
787 } catch (Standard_Failure) {
788 return aNewSO._retn();
791 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
792 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
793 aNewSO = aStudyBuilder->NewObject(theObject);
794 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
797 //Create a new GEOM_Object
798 Handle(::GEOM_Object) anObj = _impl->AddObject(theObjectID);
799 Handle(::GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
800 aFunction->SetValue(aTopology);
802 TCollection_AsciiString anEntry;
803 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
804 GEOM::GEOM_BaseObject_var obj = GetObject(anEntry.ToCString());
806 //Set the study entry of the published GEOM_Object
807 obj->SetStudyEntry(aNewSO->GetID());
809 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
810 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
811 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
812 CORBA::String_var objStr = _orb->object_to_string(obj);
813 anIOR->SetValue(objStr.in());
816 // add object to the use case tree
817 // (to support tree representation customization and drag-n-drop)
818 anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
820 // Return the created in the Study SObject
821 return aNewSO._retn();
824 //============================================================================
825 // function : ComponentDataType()
827 //============================================================================
828 char* GEOM_Gen_i::ComponentDataType()
830 return CORBA::string_dup("GEOM");
833 //============================================================================
834 // function : AddInStudy
836 //============================================================================
837 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (GEOM::GEOM_BaseObject_ptr theObject,
839 GEOM::GEOM_BaseObject_ptr theFather)
841 SALOMEDS::SObject_var aResultSO;
842 SALOMEDS::Study_var aStudy = getStudyServant();
843 if(theObject->_is_nil() || aStudy->_is_nil()) return aResultSO;
845 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
846 CORBA::String_var IOR;
848 if(!theFather->_is_nil()) {
849 IOR = _orb->object_to_string(theFather);
850 SALOMEDS::SObject_wrap aFatherSO = aStudy->FindObjectIOR(IOR.in());
851 if(aFatherSO->_is_nil()) return aResultSO._retn();
852 aResultSO = aStudyBuilder->NewObject(aFatherSO);
853 //aStudyBuilder->Addreference(aResultSO, aResultSO);
856 aResultSO = PublishInStudy(aResultSO, theObject, theName);
857 if(aResultSO->_is_nil()) return aResultSO._retn();
859 GEOM::ListOfGBO_var aList = theObject->GetDependency();
860 Standard_Integer aLength = aList->length();
861 if(aLength < 1) return aResultSO._retn();
863 //Publish the arguments
864 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
865 for(Standard_Integer i = 0; i< aLength; i++) {
866 GEOM::GEOM_BaseObject_var anObject = aList[i];
867 if(anObject->_is_nil()) continue;
868 IOR = _orb->object_to_string(anObject);
869 SALOMEDS::SObject_wrap aSO = aStudy->FindObjectIOR(IOR.in());
870 if(aSO->_is_nil()) continue;
871 CORBA::String_var anID = aSO->GetID();
872 if ( aPrevID == anID.in() ) continue;
874 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
875 aStudyBuilder->Addreference(aSubSO, aSO);
876 aStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
879 return aResultSO._retn();
882 //============================================================================
883 // function : RestoreSubShapesO
884 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
885 // To be used from python scripts out of geompy.addToStudy (non-default usage)
886 //============================================================================
887 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (GEOM::GEOM_Object_ptr theObject,
888 const GEOM::ListOfGO& theArgs,
889 GEOM::find_shape_method theFindMethod,
890 CORBA::Boolean theInheritFirstArg,
891 CORBA::Boolean theAddPrefix)
893 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
894 SALOMEDS::Study_var aStudy = getStudyServant();
895 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject))
896 return aParts._retn();
898 // find SObject in the study if it is already published
899 CORBA::String_var anIORo = _orb->object_to_string(theObject);
900 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(anIORo.in());
901 //PTv, IMP 0020001, The salome object <aSO>
902 // is not obligatory in case of invocation from script
903 // if (CORBA::is_nil(aSO))
904 // return aParts._retn();
906 aParts = RestoreSubShapes(theObject, aSO, theArgs,
907 theFindMethod, theInheritFirstArg, theAddPrefix);
908 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
909 return aParts._retn();
912 //============================================================================
913 // function : RestoreGivenSubShapesO
914 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
915 // To be used from python scripts, generated by Dump Python.
916 //============================================================================
917 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (GEOM::GEOM_Object_ptr theObject,
918 const GEOM::ListOfGO& theArgs,
919 GEOM::find_shape_method theFindMethod,
920 CORBA::Boolean theInheritFirstArg,
921 CORBA::Boolean theAddPrefix)
923 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
924 if (CORBA::is_nil(getStudyServant()) || CORBA::is_nil(theObject))
925 return aParts._retn();
927 // find SObject in the study if it is already published
928 CORBA::String_var anIORo = _orb->object_to_string(theObject);
929 SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectIOR(anIORo.in());
930 //PTv, IMP 0020001, The salome object <aSO>
931 // is not obligatory in case of invocation from script
932 // if (CORBA::is_nil(aSO))
933 // return aParts._retn();
935 aParts = RestoreGivenSubShapes(theObject, aSO, theArgs,
936 theFindMethod, theInheritFirstArg, theAddPrefix);
937 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
938 return aParts._retn();
941 //============================================================================
942 // function : RestoreSubShapesSO
943 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
944 // To be used from GUI and from geompy.addToStudy
945 //============================================================================
946 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::SObject_ptr theSObject,
947 const GEOM::ListOfGO& theArgs,
948 GEOM::find_shape_method theFindMethod,
949 CORBA::Boolean theInheritFirstArg,
950 CORBA::Boolean theAddPrefix)
952 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
953 if (CORBA::is_nil(getStudyServant()) || CORBA::is_nil(theSObject))
954 return aParts._retn();
956 SALOMEDS::GenericAttribute_var anAttr;
957 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
958 return aParts._retn();
960 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
961 CORBA::String_var anIORso = anAttrIOR->Value();
963 // get Object from SObject
964 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
965 if (CORBA::is_nil(anO))
966 return aParts._retn();
968 aParts = RestoreSubShapes(anO, theSObject, theArgs,
969 theFindMethod, theInheritFirstArg, theAddPrefix);
970 return aParts._retn();
973 //============================================================================
974 // function : addToListOfGO
975 // purpose : static local function
976 //============================================================================
977 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
978 GEOM::ListOfGO& theList )
980 const int oldLen = theList.length();
981 theList.length(oldLen + 1);
982 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
985 //============================================================================
986 // function : addToListOfGO
987 // purpose : static local function
988 //============================================================================
989 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
990 GEOM::ListOfGO& theTrgList )
992 const int oldLen = theTrgList.length();
993 const int srcLen = theSrcList.length();
994 theTrgList.length(oldLen + srcLen);
995 for( int i = 0; i < srcLen; i++ )
996 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
999 //============================================================================
1000 // function : RestoreSubShapes
1001 // purpose : Private method. Works only if both theObject and theSObject
1002 // are defined, and does not check, if they correspond to each other.
1003 //============================================================================
1004 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(GEOM::GEOM_Object_ptr theObject,
1005 SALOMEDS::SObject_ptr theSObject,
1006 const GEOM::ListOfGO& theArgs,
1007 GEOM::find_shape_method theFindMethod,
1008 CORBA::Boolean theInheritFirstArg,
1009 CORBA::Boolean theAddPrefix)
1011 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1012 SALOMEDS::Study_var aStudy = getStudyServant();
1013 //PTv, IMP 0020001, The salome object <theSObject>
1014 // is not obligatory in case of invocation from script
1015 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1016 return aParts._retn();
1018 // For Dump Python (mantis issue 0020768)
1019 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
1021 // Arguments to be published
1022 GEOM::ListOfGO_var aList;
1024 // If theArgs list is empty, we try to publish all arguments,
1025 // otherwise publish only passed args
1026 Standard_Integer nbArgsActual = -1; // -1 means unknown
1027 Standard_Integer aLength = theArgs.length();
1029 aList = new GEOM::ListOfGO;
1030 aList->length(aLength);
1031 for (int i = 0; i < aLength; i++) {
1032 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1036 // Get all arguments
1037 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1038 aLength = boList->length();
1039 aList = new GEOM::ListOfGO;
1040 aList->length(aLength);
1041 for (int i = 0; i < aLength; i++)
1042 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1043 nbArgsActual = aLength;
1047 return aParts._retn();
1049 if (theInheritFirstArg || (nbArgsActual == 1)) {
1050 // Do not publish argument's reflection,
1051 // but only reconstruct its published sub-shapes
1053 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1054 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1056 // remember restored objects for Python Dump
1057 addToListOfGO(aList[0], anOutArgs);
1059 aParts = RestoreSubShapesOneLevel(anArgSO, theSObject, theObject,
1060 anOutArgs, theFindMethod, theAddPrefix);
1062 // set the color of the transformed shape to the color of initial shape
1063 theObject->SetColor(aList[0]->GetColor());
1065 if (theObject->GetShapeType() == GEOM::VERTEX) {
1066 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1067 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1068 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1070 if (!CORBA::is_nil(anArgSO))
1071 anArgSO->UnRegister();
1074 // Get interface, containing method, which we will use to reconstruct sub-shapes
1075 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1076 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1077 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1079 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1080 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1082 // Reconstruct arguments and tree of sub-shapes of the arguments
1083 CORBA::String_var anIOR;
1084 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1085 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
1086 for (Standard_Integer i = 0; i < aLength; i++)
1088 GEOM::GEOM_Object_var anArgO = aList[i];
1089 if (!CORBA::is_nil(anArgO)) {
1090 anIOR = _orb->object_to_string(anArgO);
1091 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1092 TCollection_AsciiString anArgName;
1093 if (CORBA::is_nil(anArgSO)) {
1095 anArgName += TCollection_AsciiString(i);
1098 anArgName = anArgSO->GetName();
1101 // Find a sub-shape of theObject in place of the argument
1102 GEOM::GEOM_Object_var aSubO;
1103 switch (theFindMethod) {
1104 case GEOM::FSM_GetInPlace:
1107 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1110 case GEOM::FSM_MultiTransformed:
1112 // Only for Multi-transformations
1113 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1114 if (!CORBA::is_nil(anArgOTrsf)) {
1115 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1116 Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1117 Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1118 anArgOTrsfFun->SetDescription("");
1119 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1122 Handle(::GEOM_Function) anOFun = theObject->GetLastFunction();
1123 if (!anOFun.IsNull()) {
1124 CORBA::String_var entryArg = anArgO->GetEntry();
1125 Handle(::GEOM_Object) anArgOImpl = _impl->GetObject(entryArg);
1126 if (!anArgOImpl.IsNull()) {
1127 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1128 TopoDS_Shape aMultiArgShape;
1129 //GEOM::GEOM_Object_var anArgOMulti; // ???
1130 switch (anOFun->GetType()) {
1133 GEOMImpl_ITranslate aTI (anOFun);
1134 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1135 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1140 GEOMImpl_ITranslate aTI (anOFun);
1141 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1146 GEOMImpl_IRotate aTI (anOFun);
1147 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1152 GEOMImpl_IRotate aTI (anOFun);
1153 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1159 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1160 Handle(::GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1161 anArgOMultiFun->SetDescription("");
1162 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1168 case GEOM::FSM_Transformed:
1170 // transformation, cannot use GetInPlace, operate with indices
1171 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1172 if (anIDs->length() > 1) {
1174 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1175 if (!CORBA::is_nil(aSubO))
1176 aGroupOp->UnionIDs(aSubO, anIDs);
1178 else if (anIDs->length() > 0) {
1180 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1184 case GEOM::FSM_GetSame:
1187 aSubO = aShapesOp->GetSame(theObject, anArgO);
1190 case GEOM::FSM_GetShapesOnShape:
1192 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1193 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1194 (short)GEOM::SOLID, GEOM::ST_ONIN);
1197 case GEOM::FSM_GetInPlaceByHistory:
1199 // Use GetInPlaceByHistory
1200 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1207 if (!CORBA::is_nil(aSubO)) {
1208 // remember restored objects for Python Dump
1209 addToListOfGO(anArgO, anOutArgs);
1211 // add to parts list
1212 addToListOfGO( aSubO, aParts );
1214 // Publish the sub-shape
1215 SALOMEDS::SObject_var aSubSO;
1216 if (!CORBA::is_nil(theSObject)) {
1217 TCollection_AsciiString aSubName;
1221 aSubName += anArgName;
1222 aSubSO = aStudyBuilder->NewObject(theSObject);
1223 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1225 aSubO->SetColor(anArgO->GetColor());
1227 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1228 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1229 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1230 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1234 if (!CORBA::is_nil(anArgSO)) {
1235 // Restore published sub-shapes of the argument
1236 GEOM::ListOfGO_var aSubParts;
1237 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1238 // pass theObject, because only it has the history
1239 aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO,
1240 theObject, anOutArgs, theFindMethod, theAddPrefix);
1242 aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO,
1243 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1244 // add to parts list
1245 addToListOfGO( aSubParts, aParts );
1248 else { // GetInPlace failed, try to build from published parts
1249 if (!CORBA::is_nil(anArgSO)) {
1250 SALOMEDS::SObject_var aSubSO;
1251 if (!CORBA::is_nil(theSObject))
1253 aSubSO = aStudyBuilder->NewObject(theSObject);
1254 useCaseBuilder->AppendTo( theSObject, aSubSO );
1257 // Restore published sub-shapes of the argument
1258 GEOM::ListOfGO_var aSubParts =
1259 RestoreSubShapesOneLevel(anArgSO, aSubSO,
1260 theObject, anOutArgs, theFindMethod, theAddPrefix);
1262 // add to parts list
1263 addToListOfGO( aSubParts, aParts );
1265 if (aSubParts->length() > 0) {
1266 // remember restored objects for Python Dump
1267 addToListOfGO(anArgO, anOutArgs);
1269 // try to build an argument from a set of its sub-shapes,
1270 // that published and will be reconstructed
1271 if (aSubParts->length() > 1) {
1272 aSubO = aShapesOp->MakeCompound(aSubParts);
1273 // add to parts list
1274 addToListOfGO( aSubO, aParts );
1277 aSubO = aSubParts[0];
1279 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1280 // Publish the sub-shape
1281 TCollection_AsciiString aSubName;
1283 aSubName = "from_parts_of_";
1285 aSubName += anArgName;
1286 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1288 aSubO->SetColor(anArgO->GetColor());
1290 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1291 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1292 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1293 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1297 else if (!CORBA::is_nil(aSubSO)) {
1298 // remove created aSubSO, because no parts have been found
1299 aStudyBuilder->RemoveObject(aSubSO);
1302 } // try to build from published parts
1303 if (!CORBA::is_nil(anArgSO))
1304 anArgSO->UnRegister();
1306 } // process arguments
1308 std::set<std::string> anObjEntryMap;
1309 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1311 int nb = aParts->length();
1312 aResParts->length(nb);
1315 Handle(::GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry());
1316 Handle(::GEOM_Function) aFunction = aMainObj->GetLastFunction();
1317 GEOM::TPythonDump pd (aFunction, true);
1320 for ( ; i < nb; i++ )
1322 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1323 if (CORBA::is_nil(anObj))
1325 char* anEntry = anObj->GetEntry();
1326 if (anObjEntryMap.count(anEntry))
1327 continue; // already treated
1328 anObjEntryMap.insert(anEntry);
1329 aResParts[nbRes++] = anObj;
1330 // clear python dump of object
1331 Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry);
1332 Handle(::GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1333 if ( !anObjFun.IsNull() )
1334 anObjFun->SetDescription( "" );
1340 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1341 //i = 0; nb = theArgs.length(); j = 0;
1342 i = 0; nb = anOutArgs->length(); j = 0;
1343 for ( ; i < nb; i++ )
1345 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1346 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1347 if (CORBA::is_nil(anObj))
1349 Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry());
1355 pd <<"]" << ", " <<"GEOM.";
1356 switch (theFindMethod) {
1357 case GEOM::FSM_GetInPlace:
1358 pd << "FSM_GetInPlace"; break;
1359 case GEOM::FSM_MultiTransformed:
1360 pd << "FSM_MultiTransformed"; break;
1361 case GEOM::FSM_Transformed:
1362 pd << "FSM_Transformed"; break;
1363 case GEOM::FSM_GetSame:
1364 pd << "FSM_GetSame"; break;
1365 case GEOM::FSM_GetShapesOnShape:
1366 pd << "FSM_GetShapesOnShape"; break;
1367 case GEOM::FSM_GetInPlaceByHistory:
1369 pd << "FSM_GetInPlaceByHistory"; break;
1371 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1373 aResParts->length(nbRes);
1374 return aResParts._retn();
1377 //============================================================================
1378 // function : RestoreSubShapesOneLevel
1379 // purpose : Private method
1380 //============================================================================
1381 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO,
1382 SALOMEDS::SObject_ptr theNewSO,
1383 GEOM::GEOM_Object_ptr theNewO,
1384 GEOM::ListOfGO& theOutArgs,
1385 GEOM::find_shape_method theFindMethod,
1386 CORBA::Boolean theAddPrefix)
1389 SALOMEDS::Study_var aStudy = getStudyServant();
1390 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1391 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1392 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) ||
1393 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1394 return aParts._retn();
1396 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1397 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
1399 // Get interface, containing method, which we will use to reconstruct sub-shapes
1400 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1401 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1402 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1404 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1405 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1407 // Reconstruct published sub-shapes
1408 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO);
1411 for (it->Init(); it->More(); it->Next()) {
1414 aParts->length(aLen);
1416 for (it->Init(); it->More(); it->Next()) {
1417 SALOMEDS::SObject_var anOldSubSO = it->Value();
1419 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1421 SALOMEDS::GenericAttribute_var anAttr;
1422 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1423 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1424 GEOM::GEOM_Object_var anOldSubO =
1425 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1426 if (!CORBA::is_nil(anOldSubO)) {
1427 // Find a sub-shape of theNewO in place of anOldSubO
1428 GEOM::GEOM_Object_var aNewSubO;
1429 switch (theFindMethod) {
1430 case GEOM::FSM_GetInPlace:
1433 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1436 case GEOM::FSM_MultiTransformed:
1438 // Only for Multi-transformations
1439 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1440 if (!CORBA::is_nil(anArgOTrsf)) {
1441 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1442 Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1443 Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1444 anArgOTrsfFun->SetDescription("");
1445 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1449 case GEOM::FSM_Transformed:
1451 // transformation, cannot use GetInPlace, operate with indices
1452 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1453 if (anIDs->length() > 1) {
1455 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1456 if (!CORBA::is_nil(aNewSubO))
1457 aGroupOp->UnionIDs(aNewSubO, anIDs);
1461 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1465 case GEOM::FSM_GetSame:
1468 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1471 case GEOM::FSM_GetShapesOnShape:
1473 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1474 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1475 (short)GEOM::SOLID, GEOM::ST_ONIN);
1478 case GEOM::FSM_GetInPlaceByHistory:
1480 // Use GetInPlaceByHistory
1481 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1488 if (!CORBA::is_nil(aNewSubO)) {
1489 // remember restored objects for Python Dump
1490 addToListOfGO(anOldSubO, theOutArgs);
1492 // add the part to the list
1493 aParts[i] = aNewSubO;
1495 // add to parts list
1496 addToListOfGO( aNewSubO, aNewParts );
1498 SALOMEDS::SObject_var aNewSubSO;
1499 if (!CORBA::is_nil(theNewSO)) {
1500 // Publish the sub-shape
1501 TCollection_AsciiString aSubName;
1505 aSubName += anArgName;
1506 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1507 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
1509 aNewSubO->SetColor(anOldSubO->GetColor());
1511 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1512 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1513 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1514 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1517 SALOMEDS::SObject_wrap aReferenceSO = aStudyBuilder->NewObject( aNewSubSO );
1518 aStudyBuilder->Addreference( aReferenceSO, anOldSubSO );
1519 useCaseBuilder->AppendTo( theNewSO, aReferenceSO );
1521 // Restore published sub-shapes of the argument
1522 GEOM::ListOfGO_var aSubParts;
1523 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1524 // pass the main shape as Object, because only it has the history
1525 aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1526 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1528 aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1529 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1530 // add to parts list
1531 addToListOfGO( aSubParts, aNewParts );
1533 else { // GetInPlace failed, try to build from published parts
1534 SALOMEDS::SObject_var aNewSubSO;
1535 if (!CORBA::is_nil(theNewSO))
1537 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1538 useCaseBuilder->AppendTo( theNewSO, aNewSubSO );
1540 // Restore published sub-shapes of the argument
1541 GEOM::ListOfGO_var aSubParts =
1542 RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1543 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1544 // add to parts list
1545 addToListOfGO( aSubParts, aNewParts );
1547 if (aSubParts->length() > 0) {
1548 // remember restored objects for Python Dump
1549 addToListOfGO(anOldSubO, theOutArgs);
1551 // try to build an object from a set of its sub-shapes,
1552 // that published and will be reconstructed
1553 if (aSubParts->length() > 1) {
1554 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1555 // add to parts list
1556 addToListOfGO( aNewSubO, aNewParts );
1559 aNewSubO = aSubParts[0];
1562 if (!CORBA::is_nil(aNewSubO)) {
1563 // add the part to the list
1564 aSubParts[i] = aNewSubO;
1567 // Publish the sub-shape
1568 if (!CORBA::is_nil(aNewSubSO)) {
1569 TCollection_AsciiString aSubName;
1571 aSubName = "from_parts_of_";
1573 aSubName += anArgName;
1574 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
1576 aNewSubO->SetColor(anOldSubO->GetColor());
1578 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1579 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1580 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1581 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1586 else if (!CORBA::is_nil(aNewSubSO)) {
1587 // remove created aSubSO, because no parts have been found
1588 aStudyBuilder->RemoveObject(aNewSubSO);
1590 } // try to build from published parts
1593 } // iterate on published sub-shapes
1596 // add to parts list
1597 addToListOfGO( aNewParts, aParts );
1598 return aParts._retn();
1601 //============================================================================
1602 // function : RestoreGivenSubShapes
1603 // purpose : Private method. Works only if both theObject and theSObject
1604 // are defined, and does not check, if they correspond to each other.
1605 // List theArgs in this case contains not only operation arguments,
1606 // but also all subshapes, which must be published.
1607 //============================================================================
1608 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(GEOM::GEOM_Object_ptr theObject,
1609 SALOMEDS::SObject_ptr theSObject,
1610 const GEOM::ListOfGO& theArgs,
1611 GEOM::find_shape_method theFindMethod,
1612 CORBA::Boolean theInheritFirstArg,
1613 CORBA::Boolean theAddPrefix)
1615 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1616 SALOMEDS::Study_var aStudy = getStudyServant();
1617 //PTv, IMP 0020001, The salome object <theSObject>
1618 // is not obligatory in case of invocation from script
1619 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1620 return aParts._retn();
1622 // If theArgs list is empty, nothing to do
1623 Standard_Integer aLength = theArgs.length();
1625 return aParts._retn();
1627 // Get all arguments
1628 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1629 Standard_Integer nbOpArgs = anOpArgsList->length();
1630 Standard_Integer nbArgsActual = nbOpArgs;
1632 // If anOpArgsList list is empty, nothing to do
1633 if (nbArgsActual == 0)
1634 return aParts._retn();
1636 // Entries of arguments and subshapes
1637 std::set<std::string> anArgs;
1638 for (int i = 0; i < aLength; i++) {
1639 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1640 anArgs.insert(anEntry.in());
1643 // Arguments to be published
1644 // We try to publish all arguments, that are in theArgs list
1645 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1646 aList->length(nbArgsActual);
1649 for (int j = 0; j < nbArgsActual; j++) {
1650 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1651 if (anArgs.count(anEntry.in())) {
1652 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1657 //aList->length(nbArgsActual);
1659 if (nbArgsActual < 1)
1660 return aParts._retn();
1662 if (theInheritFirstArg || (nbOpArgs == 1)) {
1663 // Do not publish argument's reflection,
1664 // but only reconstruct its published sub-shapes
1666 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1667 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1669 aParts = RestoreGivenSubShapesOneLevel(anArgSO, theSObject, theObject,
1670 anArgs, theFindMethod, theAddPrefix);
1672 // set the color of the transformed shape to the color of initial shape
1673 theObject->SetColor(aList[0]->GetColor());
1675 if (theObject->GetShapeType() == GEOM::VERTEX) {
1676 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1677 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1678 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1681 anArgSO->UnRegister();
1684 // Get interface, containing method, which we will use to reconstruct sub-shapes
1685 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1686 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1687 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1689 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1690 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1692 // Reconstruct arguments and tree of sub-shapes of the arguments
1693 CORBA::String_var anIOR;
1694 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1695 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
1696 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1698 GEOM::GEOM_Object_var anArgO = aList[i];
1699 if (!CORBA::is_nil(anArgO)) {
1700 anIOR = _orb->object_to_string(anArgO);
1701 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1702 TCollection_AsciiString anArgName;
1703 if (CORBA::is_nil(anArgSO)) {
1705 anArgName += TCollection_AsciiString(i);
1708 anArgName = anArgSO->GetName();
1711 // Find a sub-shape of theObject in place of the argument
1712 GEOM::GEOM_Object_var aSubO;
1713 switch (theFindMethod) {
1714 case GEOM::FSM_GetInPlace:
1717 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1720 case GEOM::FSM_MultiTransformed:
1722 // Only for Multi-transformations
1723 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1724 if (!CORBA::is_nil(anArgOTrsf)) {
1725 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1726 Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1727 Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1728 anArgOTrsfFun->SetDescription("");
1729 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1733 case GEOM::FSM_Transformed:
1735 // transformation, cannot use GetInPlace, operate with indices
1736 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1737 if (anIDs->length() > 1) {
1739 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1740 if (!CORBA::is_nil(aSubO))
1741 aGroupOp->UnionIDs(aSubO, anIDs);
1743 else if (anIDs->length() > 0) {
1745 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1749 case GEOM::FSM_GetSame:
1752 aSubO = aShapesOp->GetSame(theObject, anArgO);
1755 case GEOM::FSM_GetShapesOnShape:
1757 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1758 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1759 (short)GEOM::SOLID, GEOM::ST_ONIN);
1762 case GEOM::FSM_GetInPlaceByHistory:
1764 // Use GetInPlaceByHistory
1765 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1772 if (!CORBA::is_nil(aSubO)) {
1773 // add to parts list
1774 addToListOfGO( aSubO, aParts );
1776 // Publish the sub-shape
1777 SALOMEDS::SObject_var aSubSO;
1778 if (!CORBA::is_nil(theSObject)) {
1779 TCollection_AsciiString aSubName;
1783 aSubName += anArgName;
1784 aSubSO = aStudyBuilder->NewObject(theSObject);
1785 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1787 aSubO->SetColor(anArgO->GetColor());
1789 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1790 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1791 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1792 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1796 if (!CORBA::is_nil(anArgSO)) {
1797 // Restore published sub-shapes of the argument
1798 GEOM::ListOfGO_var aSubParts;
1799 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1800 // pass theObject, because only it has the history
1801 aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1802 theObject, anArgs, theFindMethod, theAddPrefix);
1804 aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1805 aSubO, anArgs, theFindMethod, theAddPrefix);
1806 // add to parts list
1807 addToListOfGO( aSubParts, aParts );
1810 else { // GetInPlace failed, try to build from published parts
1811 if (!CORBA::is_nil(anArgSO)) {
1812 SALOMEDS::SObject_var aSubSO;
1813 if (!CORBA::is_nil(theSObject))
1815 aSubSO = aStudyBuilder->NewObject(theSObject);
1816 useCaseBuilder->AppendTo( theSObject, aSubSO );
1818 // Restore published sub-shapes of the argument
1819 GEOM::ListOfGO_var aSubParts =
1820 RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1821 theObject, anArgs, theFindMethod, theAddPrefix);
1823 // add to parts list
1824 addToListOfGO( aSubParts, aParts );
1826 if (aSubParts->length() > 0) {
1827 // try to build an argument from a set of its sub-shapes,
1828 // that published and will be reconstructed
1829 if (aSubParts->length() > 1) {
1830 aSubO = aShapesOp->MakeCompound(aSubParts);
1831 // add to parts list
1832 addToListOfGO( aSubO, aParts );
1835 aSubO = aSubParts[0];
1837 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1838 // Publish the sub-shape
1839 TCollection_AsciiString aSubName;
1841 aSubName = "from_parts_of_";
1843 aSubName += anArgName;
1844 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1846 aSubO->SetColor(anArgO->GetColor());
1848 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1849 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1850 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1851 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1855 else if (!CORBA::is_nil(aSubSO)) {
1856 // remove created aSubSO, because no parts have been found
1857 aStudyBuilder->RemoveObject(aSubSO);
1860 } // try to build from published parts
1861 anArgSO->UnRegister();
1863 } // process arguments
1865 std::set<std::string> anObjEntryMap;
1866 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1868 int nb = aParts->length();
1869 aResParts->length(nb);
1872 Handle(::GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry());
1873 Handle(::GEOM_Function) aFunction = aMainObj->GetLastFunction();
1874 GEOM::TPythonDump pd (aFunction, true);
1877 for ( ; i < nb; i++ )
1879 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1880 if (CORBA::is_nil(anObj))
1882 char* anEntry = anObj->GetEntry();
1883 if (anObjEntryMap.count(anEntry))
1884 continue; // already treated
1885 anObjEntryMap.insert(anEntry);
1886 aResParts[nbRes++] = anObj;
1887 // clear python dump of object
1888 Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry);
1889 Handle(::GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1890 if ( !anObjFun.IsNull() )
1891 anObjFun->SetDescription( "" );
1897 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1898 i = 0; nb = theArgs.length(); j = 0;
1899 for ( ; i < nb; i++ )
1901 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1902 if (CORBA::is_nil(anObj))
1904 Handle(::GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry());
1910 pd <<"]" << ", " <<"GEOM.";
1911 switch (theFindMethod) {
1912 case GEOM::FSM_GetInPlace:
1913 pd << "FSM_GetInPlace"; break;
1914 case GEOM::FSM_MultiTransformed:
1915 pd << "FSM_MultiTransformed"; break;
1916 case GEOM::FSM_Transformed:
1917 pd << "FSM_Transformed"; break;
1918 case GEOM::FSM_GetSame:
1919 pd << "FSM_GetSame"; break;
1920 case GEOM::FSM_GetShapesOnShape:
1921 pd << "FSM_GetShapesOnShape"; break;
1922 case GEOM::FSM_GetInPlaceByHistory:
1924 pd << "FSM_GetInPlaceByHistory"; break;
1926 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1928 aResParts->length(nbRes);
1929 return aResParts._retn();
1932 //============================================================================
1933 // function : RestoreGivenSubShapesOneLevel
1934 // purpose : Private method
1935 //============================================================================
1936 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO,
1937 SALOMEDS::SObject_ptr theNewSO,
1938 GEOM::GEOM_Object_ptr theNewO,
1939 std::set<std::string> theArgs,
1940 GEOM::find_shape_method theFindMethod,
1941 CORBA::Boolean theAddPrefix)
1944 SALOMEDS::Study_var aStudy = getStudyServant();
1945 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1946 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1947 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) ||
1948 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1949 return aParts._retn();
1951 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1952 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
1954 // Get interface, containing method, which we will use to reconstruct sub-shapes
1955 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1956 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1957 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1959 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1960 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1962 // Reconstruct published sub-shapes
1963 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO);
1966 for (it->Init(); it->More(); it->Next()) {
1969 aParts->length(aLen);
1971 for (it->Init(); it->More(); it->Next()) {
1972 SALOMEDS::SObject_var anOldSubSO = it->Value();
1974 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1976 SALOMEDS::GenericAttribute_var anAttr;
1977 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1978 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1979 GEOM::GEOM_Object_var anOldSubO =
1980 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1982 bool okToContinue = false;
1984 if (!CORBA::is_nil(anOldSubO)) {
1985 CORBA::String_var anEntry = anOldSubO->GetEntry();
1986 okToContinue = theArgs.count(anEntry.in());
1990 // Find a sub-shape of theNewO in place of anOldSubO
1991 GEOM::GEOM_Object_var aNewSubO;
1992 switch (theFindMethod) {
1993 case GEOM::FSM_GetInPlace:
1996 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1999 case GEOM::FSM_MultiTransformed:
2001 // Only for Multi-transformations
2002 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
2003 if (!CORBA::is_nil(anArgOTrsf)) {
2004 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
2005 Handle(::GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
2006 Handle(::GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
2007 anArgOTrsfFun->SetDescription("");
2008 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
2012 case GEOM::FSM_Transformed:
2014 // transformation, cannot use GetInPlace, operate with indices
2015 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
2016 if (anIDs->length() > 1) {
2018 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
2019 if (!CORBA::is_nil(aNewSubO))
2020 aGroupOp->UnionIDs(aNewSubO, anIDs);
2024 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
2028 case GEOM::FSM_GetSame:
2031 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
2034 case GEOM::FSM_GetShapesOnShape:
2036 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
2037 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
2038 (short)GEOM::SOLID, GEOM::ST_ONIN);
2041 case GEOM::FSM_GetInPlaceByHistory:
2043 // Use GetInPlaceByHistory
2044 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2051 if (!CORBA::is_nil(aNewSubO)) {
2052 // add the part to the list
2053 aParts[i] = aNewSubO;
2055 // add to parts list
2056 addToListOfGO( aNewSubO, aNewParts );
2058 SALOMEDS::SObject_var aNewSubSO;
2059 if (!CORBA::is_nil(theNewSO)) {
2060 // Publish the sub-shape
2061 TCollection_AsciiString aSubName;
2065 aSubName += anArgName;
2066 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2067 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
2069 aNewSubO->SetColor(anOldSubO->GetColor());
2071 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2072 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2073 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2074 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2077 SALOMEDS::SObject_wrap aReferenceSO = aStudyBuilder->NewObject( aNewSubSO );
2078 aStudyBuilder->Addreference( aReferenceSO, anOldSubSO );
2079 useCaseBuilder->AppendTo( theNewSO, aReferenceSO );
2081 // Restore published sub-shapes of the argument
2082 GEOM::ListOfGO_var aSubParts;
2083 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2084 // pass the main shape as Object, because only it has the history
2085 aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2086 theNewO, theArgs, theFindMethod, theAddPrefix);
2088 aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2089 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2090 // add to parts list
2091 addToListOfGO( aSubParts, aNewParts );
2093 else { // GetInPlace failed, try to build from published parts
2094 SALOMEDS::SObject_var aNewSubSO;
2095 if (!CORBA::is_nil(theNewSO))
2097 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2098 useCaseBuilder->AppendTo( theNewSO, aNewSubSO );
2100 // Restore published sub-shapes of the argument
2101 GEOM::ListOfGO_var aSubParts =
2102 RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2103 theNewO, theArgs, theFindMethod, theAddPrefix);
2104 // add to parts list
2105 addToListOfGO( aSubParts, aNewParts );
2107 if (aSubParts->length() > 0) {
2108 // try to build an object from a set of its sub-shapes,
2109 // that published and will be reconstructed
2110 if (aSubParts->length() > 1) {
2111 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2112 // add to parts list
2113 addToListOfGO( aNewSubO, aNewParts );
2116 aNewSubO = aSubParts[0];
2119 if (!CORBA::is_nil(aNewSubO)) {
2120 // add the part to the list
2121 aSubParts[i] = aNewSubO;
2124 // Publish the sub-shape
2125 if (!CORBA::is_nil(aNewSubSO)) {
2126 TCollection_AsciiString aSubName;
2128 aSubName = "from_parts_of_";
2130 aSubName += anArgName;
2131 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
2133 aNewSubO->SetColor(anOldSubO->GetColor());
2135 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2136 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2137 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2138 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2143 else if (!CORBA::is_nil(aNewSubSO)) {
2144 // remove created aSubSO, because no parts have been found
2145 aStudyBuilder->RemoveObject(aNewSubSO);
2147 } // try to build from published parts
2150 } // iterate on published sub-shapes
2153 // add to parts list
2154 addToListOfGO( aNewParts, aParts );
2155 return aParts._retn();
2158 //============================================================================
2159 // function : register()
2160 // purpose : register 'name' in 'name_service'
2161 //============================================================================
2162 void GEOM_Gen_i::register_name(char * name)
2164 GEOM::GEOM_Gen_var g = _this();
2165 name_service->Register(g, name);
2168 //============================================================================
2169 // function : getStudyServant()
2170 // purpose : Get Study
2171 //============================================================================
2172 SALOMEDS::Study_var GEOM_Gen_i::getStudyServant()
2174 static SALOMEDS::Study_var aStudy;
2175 if(CORBA::is_nil(aStudy)){
2176 CORBA::Object_ptr anObject = name_service->Resolve("/Study");
2177 aStudy = SALOMEDS::Study::_narrow(anObject);
2182 //============================================================================
2183 // function : findOrCreateComponent()
2184 // purpose : Find root study component; create if it does not exist
2185 //============================================================================
2186 SALOMEDS::SComponent_var GEOM_Gen_i::findOrCreateComponent()
2188 SALOMEDS::SComponent_var aComponent;
2190 SALOMEDS::Study_var aStudy = getStudyServant();
2191 if (aStudy->_is_nil()) return aComponent;
2193 SALOMEDS::GenericAttribute_var anAttr;
2194 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2195 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = aStudy->GetUseCaseBuilder();
2197 aComponent = aStudy->FindComponent(ComponentDataType());
2198 if (aComponent->_is_nil()) {
2199 aComponent = aStudyBuilder->NewComponent(ComponentDataType());
2200 anAttr = aStudyBuilder->FindOrCreateAttribute(aComponent.in(), "AttributeName");
2201 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2202 aName->SetValue("Geometry");
2203 aName->UnRegister();
2204 anAttr = aStudyBuilder->FindOrCreateAttribute(aComponent.in(), "AttributePixMap");
2205 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
2206 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
2207 aPixMap->UnRegister();
2208 aStudyBuilder->DefineComponentInstance(aComponent.in(), (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
2209 // add component to the use case tree
2210 // (to support tree representation customization and drag-n-drop)
2211 useCaseBuilder->SetRootCurrent();
2212 useCaseBuilder->Append(aComponent.in()); // component object is added as the top level item
2217 //============================================================================
2220 //============================================================================
2221 void GEOM_Gen_i::Undo()
2226 //============================================================================
2229 //============================================================================
2230 void GEOM_Gen_i::Redo()
2235 //============================================================================
2236 // function : GetIBasicOperations
2238 //============================================================================
2239 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations()
2240 throw ( SALOME::SALOME_Exception )
2242 Unexpect aCatch(SALOME_SalomeException);
2243 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2245 GEOM::GEOM_Gen_ptr engine = _this();
2247 //transfer reference on engine
2248 GEOM_IBasicOperations_i* aServant =
2249 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations());
2251 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2252 // activate the CORBA servant
2253 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2254 return operations._retn();
2257 //============================================================================
2258 // function : GetITransformOperations
2260 //============================================================================
2261 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations()
2262 throw ( SALOME::SALOME_Exception )
2264 Unexpect aCatch(SALOME_SalomeException);
2265 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2267 GEOM::GEOM_Gen_ptr engine = _this();
2269 GEOM_ITransformOperations_i* aServant =
2270 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations());
2272 // activate the CORBA servant
2273 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2274 return operations._retn();
2277 //============================================================================
2278 // function : GetI3DPrimOperations
2280 //============================================================================
2281 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations()
2282 throw ( SALOME::SALOME_Exception )
2284 Unexpect aCatch(SALOME_SalomeException);
2285 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2287 GEOM::GEOM_Gen_ptr engine = _this();
2289 GEOM_I3DPrimOperations_i* aServant =
2290 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations());
2291 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2293 // activate the CORBA servant
2294 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2295 return operations._retn();
2298 //============================================================================
2299 // function : GetIShapesOperations
2301 //============================================================================
2302 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations()
2303 throw ( SALOME::SALOME_Exception )
2305 Unexpect aCatch(SALOME_SalomeException);
2306 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2308 GEOM::GEOM_Gen_ptr engine = _this();
2310 GEOM_IShapesOperations_i* aServant =
2311 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations());
2313 // activate the CORBA servant
2314 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2315 return operations._retn();
2318 //============================================================================
2319 // function : GetIBlocksOperations
2321 //============================================================================
2322 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations()
2323 throw ( SALOME::SALOME_Exception )
2325 Unexpect aCatch(SALOME_SalomeException);
2326 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2328 GEOM::GEOM_Gen_ptr engine = _this();
2330 GEOM_IBlocksOperations_i* aServant =
2331 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations());
2333 // activate the CORBA servant
2334 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2335 return operations._retn();
2338 //============================================================================
2339 // function : GetIBooleanOperations
2341 //============================================================================
2342 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations()
2343 throw ( SALOME::SALOME_Exception )
2345 Unexpect aCatch(SALOME_SalomeException);
2346 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2348 GEOM::GEOM_Gen_ptr engine = _this();
2350 GEOM_IBooleanOperations_i* aServant =
2351 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations());
2353 // activate the CORBA servant
2354 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2355 return operations._retn();
2358 //============================================================================
2359 // function : GetICurvesOperations
2361 //============================================================================
2362 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations()
2363 throw ( SALOME::SALOME_Exception )
2365 Unexpect aCatch(SALOME_SalomeException);
2366 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2368 GEOM::GEOM_Gen_ptr engine = _this();
2370 GEOM_ICurvesOperations_i* aServant =
2371 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations());
2373 // activate the CORBA servant
2374 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2375 return operations._retn();
2378 //============================================================================
2379 // function : GetILocalOperations
2381 //============================================================================
2382 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations()
2383 throw ( SALOME::SALOME_Exception )
2385 Unexpect aCatch(SALOME_SalomeException);
2386 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2388 GEOM::GEOM_Gen_ptr engine = _this();
2390 GEOM_ILocalOperations_i* aServant =
2391 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations());
2393 // activate the CORBA servant
2394 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2395 return operations._retn();
2398 //============================================================================
2399 // function : GetIHealingOperations
2401 //============================================================================
2402 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations()
2403 throw ( SALOME::SALOME_Exception )
2405 Unexpect aCatch(SALOME_SalomeException);
2406 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2408 GEOM::GEOM_Gen_ptr engine = _this();
2410 GEOM_IHealingOperations_i* aServant =
2411 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations());
2413 // activate the CORBA servant
2414 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2415 return operations._retn();
2418 //============================================================================
2419 // function : GetIInsertOperations
2421 //============================================================================
2422 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations()
2423 throw ( SALOME::SALOME_Exception )
2425 Unexpect aCatch(SALOME_SalomeException);
2426 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2428 GEOM::GEOM_Gen_ptr engine = _this();
2430 GEOM_IInsertOperations_i* aServant =
2431 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations());
2433 // activate the CORBA servant
2434 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2435 return operations._retn();
2438 //============================================================================
2439 // function : GetIMeasureOperations
2441 //============================================================================
2442 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations()
2443 throw ( SALOME::SALOME_Exception )
2445 Unexpect aCatch(SALOME_SalomeException);
2446 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2448 GEOM::GEOM_Gen_ptr engine = _this();
2450 GEOM_IMeasureOperations_i* aServant =
2451 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations());
2453 // activate the CORBA servant
2454 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2455 return operations._retn();
2458 //============================================================================
2459 // function : GetIGroupOperations
2461 //============================================================================
2462 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations()
2463 throw ( SALOME::SALOME_Exception )
2465 Unexpect aCatch(SALOME_SalomeException);
2466 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2468 GEOM::GEOM_Gen_ptr engine = _this();
2470 GEOM_IGroupOperations_i* aServant =
2471 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations());
2473 // activate the CORBA servant
2474 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2475 return operations._retn();
2478 //============================================================================
2479 // function : GetIFieldOperations
2481 //============================================================================
2482 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations()
2483 throw ( SALOME::SALOME_Exception )
2485 Unexpect aCatch(SALOME_SalomeException);
2486 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2488 GEOM::GEOM_Gen_ptr engine = _this();
2490 GEOM_IFieldOperations_i* aServant =
2491 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations());
2493 // activate the CORBA servant
2494 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2495 return operations._retn();
2498 //============================================================================
2499 // function : GetPluginOperations
2501 //============================================================================
2502 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(const char* theLibName)
2503 throw ( SALOME::SALOME_Exception )
2505 Unexpect aCatch(SALOME_SalomeException);
2506 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2508 GEOM::GEOM_Gen_ptr engine = _this();
2510 GEOM::GEOM_IOperations_var operations;
2512 std::string aLibName = theLibName;
2515 // load plugin library
2516 LoadPlugin(aLibName);
2517 // create a new operations object, store its ref. in engine
2518 if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
2519 GEOM_IOperations_i* aServant = 0;
2520 aServant = myOpCreatorMap[aLibName]->Create(_poa, engine, _impl);
2521 // activate the CORBA servant
2523 operations = aServant->_this();
2526 catch (SALOME_Exception& S_ex) {
2527 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2530 return operations._retn();
2533 //============================================================================
2534 // function : LoadPlugin
2535 // purpose : load plugin library and retrieve an instance of operations creator
2536 //============================================================================
2537 void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
2539 std::string aPlatformLibName;
2541 aPlatformLibName = "lib";
2543 aPlatformLibName += theLibName;
2545 aPlatformLibName += ".dll" ;
2546 #elif defined(__APPLE__)
2547 aPlatformLibName += ".dylib";
2549 aPlatformLibName += ".so";
2552 // check, if corresponding operations are already created
2553 if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
2556 std::wstring strL = Kernel_Utils::utf8_decode_s(aPlatformLibName);
2557 const wchar_t* aPath = strL.c_str();
2559 const char* aPath = aPlatformLibName.c_str();
2561 // load plugin library
2562 LibHandle libHandle = LoadLib(aPath);
2564 LibHandle libHandle = LoadLib(aPlatformLibName.c_str());
2567 // report any error, if occurred
2569 throw(SALOME_Exception(dlerror()));
2571 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2575 // get method, returning operations creator
2576 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2577 GetOperationsCreator procHandle =
2578 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2580 UnLoadLib(libHandle);
2581 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2584 // get operations creator
2585 GEOM_GenericOperationsCreator* aCreator = procHandle();
2587 // map operations creator to a plugin name
2588 myOpCreatorMap[theLibName] = aCreator;
2591 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2596 //=============================================================================
2600 //=============================================================================
2601 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2602 const GEOM::ListOfLong& theIndices)
2604 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2605 return GEOM::GEOM_Object::_nil();
2606 CORBA::String_var entry = theMainShape->GetEntry();
2607 Handle(::GEOM_Object) aMainShape = Handle(::GEOM_Object)::DownCast
2608 ( _impl->GetObject( entry ));
2609 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2611 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2612 for(CORBA::ULong i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2614 Handle(::GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2615 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2617 TCollection_AsciiString anEntry;
2618 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2619 return GEOM::GEOM_Object::_narrow( GetObject(anEntry.ToCString()));
2622 //=============================================================================
2626 //=============================================================================
2627 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2629 CORBA::String_var anEntry = theObject->GetEntry();
2630 Handle(::GEOM_BaseObject) anObject = _impl->GetObject(anEntry, false);
2631 if (!anObject.IsNull())
2632 _impl->RemoveObject(anObject);
2635 //=================================================================================
2636 // function : GetStringFromIOR()
2637 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2638 //=================================================================================
2639 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2641 return _orb->object_to_string(theObject);
2644 //=================================================================================
2645 // function : GetIORFromString()
2646 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2647 //=================================================================================
2648 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2649 GEOM::GEOM_Object_var aGeomObject;
2650 if(strcmp(stringIOR,"") != 0){
2651 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2652 if(!CORBA::is_nil(anObject))
2653 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2655 return aGeomObject._retn();
2658 //=================================================================================
2659 // function : GetObject()
2661 //=================================================================================
2662 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (const char* theEntry)
2664 GEOM::GEOM_BaseObject_var obj;
2665 Handle(::GEOM_BaseObject) handle_object = _impl->GetObject((char*)theEntry);
2666 if (handle_object.IsNull()) return obj._retn();
2668 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2669 if (stringIOR.Length() > 1) {
2670 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2671 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2675 GEOM::GEOM_Gen_ptr engine = _this();
2676 //transfer the reference to GEOM_Object_i
2677 GEOM_BaseObject_i* servant = 0;
2678 switch( handle_object->GetType() ) {
2680 servant = new GEOM_Field_i (_poa, engine, Handle(::GEOM_Field)::DownCast( handle_object ));
2683 case GEOM_FIELD_STEP: {
2684 Handle(::GEOM_FieldStep) step = Handle(::GEOM_FieldStep)::DownCast( handle_object );
2685 Handle(::GEOM_Field) field = step->GetField();
2686 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2688 case GEOM::FDT_Bool:
2689 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2692 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2694 case GEOM::FDT_Double:
2695 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2698 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2703 servant = new GEOM_Object_i (_poa, engine, Handle(::GEOM_Object)::DownCast( handle_object ));
2705 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2707 obj = servant->_this();
2708 CORBA::String_var objStr = _orb->object_to_string(obj);
2709 TCollection_AsciiString anAscii( (char *)objStr.in() );
2710 handle_object->SetIOR( anAscii );
2714 //=================================================================================
2715 // function : hasObjectInfo()
2716 // purpose : shows if module provides information for its objects
2717 //=================================================================================
2718 bool GEOM_Gen_i::hasObjectInfo()
2723 //=================================================================================
2724 // function : getObjectInfo()
2725 // purpose : returns an information for a given object by its entry
2726 //=================================================================================
2727 char* GEOM_Gen_i::getObjectInfo(const char* entry)
2729 GEOM::GEOM_Object_var aGeomObject;
2731 SALOMEDS::SObject_var aSObj = getStudyServant()->FindObjectID( entry );
2732 SALOMEDS::SObject_var aResultSObj;
2733 if (aSObj->ReferencedObject(aResultSObj))
2734 aSObj = aResultSObj;
2736 SALOMEDS::GenericAttribute_var anAttr;
2737 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2738 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2739 CORBA::String_var aVal = anIOR->Value();
2740 anIOR->UnRegister();
2741 CORBA::Object_var anObject = getStudyServant()->ConvertIORToObject(aVal);
2742 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2744 if (!aSObj->_is_nil() )
2745 aSObj->UnRegister();
2747 const char* aTypeInfo = "Object";
2748 if ( !aGeomObject->_is_nil() ) {
2749 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2750 GEOM::ListOfLong_var anInts;
2751 GEOM::ListOfDouble_var aDbls;
2753 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations();
2754 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2756 if ( anOp->IsDone() ) {
2758 case GEOM::GEOM_IKindOfShape::COMPOUND:
2759 aTypeInfo = "Compound";
2761 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2762 aTypeInfo = "CompSolid";
2764 case GEOM::GEOM_IKindOfShape::SHELL:
2765 aTypeInfo = "Shell";
2767 case GEOM::GEOM_IKindOfShape::WIRE:
2768 if ( anInts[0] == 1 )
2769 aTypeInfo = "Closed Wire";
2770 else if ( anInts[0] == 2 )
2771 aTypeInfo = "Opened Wire";
2776 case GEOM::GEOM_IKindOfShape::SPHERE:
2777 aTypeInfo = "Sphere";
2779 case GEOM::GEOM_IKindOfShape::CYLINDER:
2780 aTypeInfo = "Cylinder";
2782 case GEOM::GEOM_IKindOfShape::BOX:
2783 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2786 case GEOM::GEOM_IKindOfShape::TORUS:
2787 aTypeInfo = "Torus";
2789 case GEOM::GEOM_IKindOfShape::CONE:
2792 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2793 aTypeInfo = "Polyhedron";
2795 case GEOM::GEOM_IKindOfShape::SOLID:
2796 aTypeInfo = "Solid";
2799 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2800 aTypeInfo = "Spherical Face";
2802 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2803 aTypeInfo = "Cylindrical Face";
2805 case GEOM::GEOM_IKindOfShape::TORUS2D:
2806 aTypeInfo = "Toroidal Face";
2808 case GEOM::GEOM_IKindOfShape::CONE2D:
2809 aTypeInfo = "Conical Face";
2811 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2814 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2815 aTypeInfo = "Elliptical Face";
2817 case GEOM::GEOM_IKindOfShape::POLYGON:
2818 aTypeInfo = "Polygon";
2820 case GEOM::GEOM_IKindOfShape::PLANE:
2821 aTypeInfo = "Plane";
2823 case GEOM::GEOM_IKindOfShape::PLANAR:
2824 aTypeInfo = "Planar Face";
2826 case GEOM::GEOM_IKindOfShape::FACE:
2830 case GEOM::GEOM_IKindOfShape::CIRCLE:
2831 aTypeInfo = "Circle";
2833 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2834 aTypeInfo = "Arc Circle";
2836 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2837 aTypeInfo = "Ellipse";
2839 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2840 aTypeInfo = "Arc Ellipse";
2842 case GEOM::GEOM_IKindOfShape::LINE:
2845 case GEOM::GEOM_IKindOfShape::SEGMENT:
2846 aTypeInfo = "Segment";
2848 case GEOM::GEOM_IKindOfShape::EDGE:
2851 case GEOM::GEOM_IKindOfShape::VERTEX:
2852 aTypeInfo = "Vertex";
2860 CORBA::String_var compType = ComponentDataType();
2861 char* anInfo = new char[strlen("Module ") + strlen(compType.in()) + strlen(", ") + strlen(aTypeInfo) + 3];
2862 sprintf(anInfo, "Module %s, %s", compType.in(), aTypeInfo);
2864 char* ret = CORBA::string_dup(anInfo);
2869 // Version information
2870 char* GEOM_Gen_i::getVersion()
2872 #if GEOM_DEVELOPMENT
2873 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2875 return CORBA::string_dup(GEOM_VERSION_STR);
2879 //=================================================================================
2880 // function : CreateFolder()
2881 // purpose : Creates and returns a new folder object
2882 //=================================================================================
2883 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2884 SALOMEDS::SObject_ptr theFather)
2886 SALOMEDS::SObject_var aFolderSO;
2888 if ( CORBA::is_nil(theFather) ) {
2889 SALOMEDS::SComponent_var aComponent = findOrCreateComponent();
2890 if (aComponent->_is_nil()) return aFolderSO._retn();
2891 theFather = SALOMEDS::SObject::_narrow(aComponent);
2893 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2895 SALOMEDS::GenericAttribute_var anAttr;
2896 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2897 // not a GEOM component object was selected
2898 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2899 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2900 if( aLocalID->Value() != 999 ) {
2901 // not a Folder object was selected
2902 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2903 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2904 // another GEOM object was selected, so get GEOM component as father object
2905 theFather = theFather->GetFatherComponent();
2907 aLocalID->UnRegister();
2910 SALOMEDS::Study_var aStudy = getStudyServant();
2911 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2912 aFolderSO = aStudyBuilder->NewObject( theFather );
2914 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2915 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2916 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2917 aLocalID->UnRegister();
2919 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2920 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2921 aName->SetValue( theName );
2922 aName->UnRegister();
2924 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2925 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2926 aPixMap->SetPixMap("ICON_FOLDER");
2927 aPixMap->UnRegister();
2929 // add object to the use case tree
2930 // (to support tree representation customization and drag-n-drop)
2931 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2932 useCaseBuilder->AppendTo( theFather, aFolderSO );
2934 return aFolderSO._retn();
2937 //=================================================================================
2938 // function : MoveToFolder()
2939 // purpose : Moves GEOM object to the specified folder
2940 //=================================================================================
2941 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2942 SALOMEDS::SObject_ptr theFolder) {
2943 GEOM::object_list_var objects = new GEOM::object_list();
2944 objects->length( 1 );
2945 SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectID( theObject->GetStudyEntry() );
2947 Move( objects, theFolder, -1 );
2950 //=================================================================================
2951 // function : MoveListToFolder()
2952 // purpose : Moves list of GEOM objects to the specified folder
2953 //=================================================================================
2954 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2955 SALOMEDS::SObject_ptr theFolder) {
2956 int aLen = theListOfGO.length();
2957 GEOM::object_list_var objects = new GEOM::object_list();
2958 objects->length( aLen );
2959 GEOM::GEOM_Object_var aGO;
2960 SALOMEDS::SObject_var aSO;
2961 for (int i = 0; i < aLen; i++) {
2962 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2963 aSO = getStudyServant()->FindObjectID( aGO->GetStudyEntry() );
2966 if ( objects->length() > 0 )
2967 Move( objects, theFolder, -1 );
2970 //=================================================================================
2971 // function : Move()
2972 // purpose : Moves objects to the specified position.
2973 // Is used in the drag-n-drop functionality.
2974 //=================================================================================
2975 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2976 SALOMEDS::SObject_ptr where,
2979 if ( CORBA::is_nil( where ) ) return;
2981 SALOMEDS::Study_var study = getStudyServant();
2982 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2983 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2984 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2985 std::string dataType = father->ComponentDataType();
2986 if ( dataType != "GEOM" ) return; // not a GEOM component
2988 SALOMEDS::SObject_var objAfter;
2989 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2990 // insert at given row -> find insertion position
2991 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2993 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2994 if ( i == row && useCaseIt->More() ) {
2995 objAfter = useCaseIt->Value();
2999 for ( CORBA::ULong i = 0; i < what.length(); i++ ) {
3000 SALOMEDS::SObject_var sobj = what[i];
3001 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
3002 // insert the object to the use case tree
3003 if ( !CORBA::is_nil( objAfter ) )
3004 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
3006 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
3010 //=======================================================================
3011 // function : GetDependencyTree
3012 // purpose : Collects dependencies of the given objects from other ones
3013 //=======================================================================
3014 SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( const GEOM::string_array& theObjectEntries )
3016 // fill in the tree structure
3017 GEOMUtils::TreeModel tree;
3020 for ( CORBA::ULong i = 0; i < theObjectEntries.length(); i++ ) {
3021 // process objects one-by-one
3022 entry = theObjectEntries[i].in();
3023 GEOM::GEOM_BaseObject_var anObj = GetObject(entry.c_str() );
3024 if ( anObj->_is_nil() )
3026 std::map< std::string, std::set<std::string> > passedEntries;
3027 GEOMUtils::LevelsList upLevelList;
3028 // get objects from which current one depends on recursively
3029 getUpwardDependency( anObj, upLevelList, passedEntries );
3030 GEOMUtils::LevelsList downLevelList;
3031 // get objects that depends on current one recursively
3032 getDownwardDependency( anObj, downLevelList, passedEntries );
3033 tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(entry, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
3036 // translation the tree into string
3037 std::string treeStr;
3038 GEOMUtils::ConvertTreeToString( tree, treeStr );
3040 // put string into stream
3041 char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
3042 int aBufferSize = strlen((char*)aBuffer);
3044 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3046 SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
3048 return aStream._retn();
3051 //=======================================================================
3052 // function : getUpwardDependency
3053 // purpose : Collects the entries of objects on that the given one depends
3054 //=======================================================================
3055 void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3056 GEOMUtils::LevelsList &upLevelList,
3057 std::map< std::string, std::set<std::string> > &passedEntries,
3059 std::string aGboEntry = gbo->GetEntry();
3060 GEOMUtils::NodeLinks anEntries;
3061 GEOMUtils::LevelInfo aLevelMap;
3063 if ( level-1 >= (int)upLevelList.size() ) {
3065 upLevelList.push_back( aLevelMap );
3067 // get the existent map
3068 aLevelMap = upLevelList.at(level-1);
3069 if ( aLevelMap.count( aGboEntry ) > 0 ) {
3070 anEntries = aLevelMap[ aGboEntry ];
3074 // get objects on that the current one depends
3075 GEOM::ListOfGBO_var depList = gbo->GetDependency();
3076 std::string aDepEntry;
3077 for( CORBA::ULong j = 0; j < depList->length(); j++ ) {
3078 if ( depList[j]->_is_nil() )
3080 aDepEntry = depList[j]->GetEntry();
3081 if ( passedEntries.count( aGboEntry ) > 0 &&
3082 passedEntries[aGboEntry].count( aDepEntry ) > 0 ) {
3083 //avoid checking the passed objects
3086 passedEntries[aGboEntry].insert( aDepEntry );
3088 anEntries.push_back( aDepEntry );
3090 // get dependencies recursively
3091 getUpwardDependency(depList[j], upLevelList, passedEntries, level+1);
3094 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboEntry, anEntries) );
3095 upLevelList[level-1] = aLevelMap;
3099 //=======================================================================
3100 // function : getDownwardDependency
3101 // purpose : Collects the entries of objects that depends on the given one
3102 //=======================================================================
3103 void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3104 GEOMUtils::LevelsList &downLevelList,
3105 std::map< std::string, std::set<std::string> > &passedEntries,
3107 std::string aGboEntry = gbo->GetEntry();
3108 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument();
3109 Handle(TDataStd_TreeNode) aNode, aRoot;
3110 Handle(::GEOM_Function) aFunction;
3111 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3112 // go through the whole OCAF tree
3113 TDataStd_ChildNodeIterator Itr( aRoot );
3114 for (; Itr.More(); Itr.Next()) {
3115 aNode = Itr.Value();
3116 aFunction = GEOM_Function::GetFunction(aNode->Label());
3117 if (aFunction.IsNull()) {
3120 TDF_Label aLabel = aFunction->GetOwnerEntry();
3121 if(aLabel.IsNull()) continue;
3122 TCollection_AsciiString anEntry;
3123 TDF_Tool::Entry(aLabel, anEntry);
3124 GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.ToCString() );
3125 if( CORBA::is_nil( geomObj ) )
3127 // get dependencies for current object in the tree
3128 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3129 if( depList->length() == 0 )
3131 std::string aGoEntry = geomObj->GetEntry();
3132 // go through dependencies of current object to check whether it depends on the given object
3133 for( CORBA::ULong i = 0; i < depList->length(); i++ ) {
3134 if ( depList[i]->_is_nil() )
3136 if ( depList[i]->_is_equivalent( gbo ) ) {
3137 // yes, the current object depends on the given object
3138 if ( passedEntries.count( aGoEntry ) > 0 &&
3139 passedEntries[aGoEntry].count( aGboEntry ) > 0 ) {
3140 //avoid checking the passed objects
3143 passedEntries[aGoEntry].insert( aGboEntry );
3144 GEOMUtils::NodeLinks anEntries;
3145 GEOMUtils::LevelInfo aLevelMap;
3146 anEntries.push_back( aGboEntry );
3147 if ( level >= (int)downLevelList.size() ) {
3148 downLevelList.push_back( aLevelMap );
3150 aLevelMap = downLevelList.at(level);
3151 if ( aLevelMap.count( aGoEntry ) > 0 ) {
3152 anEntries = aLevelMap[ aGoEntry ];
3155 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoEntry, anEntries) );
3156 downLevelList[level] = aLevelMap;
3157 // get dependencies of the current object recursively
3158 getDownwardDependency(geomObj, downLevelList, passedEntries, level+1);
3166 //==============================================================================
3167 // function : GetEntriesToReduceStudy
3168 // purpose : Fills 3 lists that is used to clean study of redundant objects
3169 //==============================================================================
3170 void GEOM_Gen_i::GetEntriesToReduceStudy(GEOM::string_array& theSelectedEntries,
3171 GEOM::string_array& theParentEntries,
3172 GEOM::string_array& theSubEntries,
3173 GEOM::string_array& theOtherEntries)
3175 std::set<std::string> aSelected, aParents, aChildren, anOthers;
3176 for ( CORBA::ULong i = 0; i < theSelectedEntries.length(); i++ ) {
3177 aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) );
3180 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument();
3181 Handle(TDataStd_TreeNode) aNode, aRoot;
3182 Handle(::GEOM_Function) aFunction;
3183 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3184 // go through the whole OCAF tree
3186 std::string anEntry;
3187 TCollection_AsciiString anAsciiEntry;
3188 TDataStd_ChildNodeIterator Itr( aRoot );
3189 for (; Itr.More(); Itr.Next()) {
3190 aNode = Itr.Value();
3191 aFunction = GEOM_Function::GetFunction(aNode->Label());
3192 if (aFunction.IsNull()) {
3195 aLabel = aFunction->GetOwnerEntry();
3198 TDF_Tool::Entry(aLabel, anAsciiEntry);
3199 anEntry = anAsciiEntry.ToCString();
3200 GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.c_str() );
3201 if( CORBA::is_nil( geomObj ) )
3204 if ( aSelected.count( anEntry ) > 0 &&
3205 aParents.count( anEntry ) == 0 ) {
3206 includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers );
3207 } else if ( aParents.count( anEntry ) == 0 &&
3208 aChildren.count( anEntry ) == 0 ) {
3209 anOthers.insert( geomObj->GetEntry() );
3213 std::set<std::string>::iterator it;
3214 std::set<std::string>::iterator foundIt;
3215 TCollection_AsciiString stringIOR;
3216 GEOM::GEOM_Object_var geomObj;
3218 // filling list of sub-objects
3219 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3220 includeSubObjects( *it, aSelected, aParents, aChildren, anOthers );
3223 // if some selected object is not a main shape,
3224 // we move it's main shapes into 'selected' list,
3225 // because they could not be modified anyhow.
3226 std::set<std::string> aToBeInSelected;
3227 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3228 Handle(::GEOM_BaseObject) handle_object = _impl->GetObject((*it).c_str(), false);
3229 if ( handle_object.IsNull() )
3232 stringIOR = handle_object->GetIOR();
3233 if ( !stringIOR.Length() > 1 )
3236 geomObj = GetIORFromString( stringIOR.ToCString() );
3237 while ( !geomObj->IsMainShape() ) {
3238 geomObj = geomObj->GetMainShape();
3239 anEntry = geomObj->GetEntry();
3241 foundIt = aParents.find( anEntry );
3242 if ( foundIt != aParents.end() )
3243 aParents.erase( foundIt );
3245 foundIt = aChildren.find( anEntry );
3246 if ( foundIt != aChildren.end() )
3247 aChildren.erase( foundIt );
3249 foundIt = anOthers.find( anEntry );
3250 if ( foundIt != anOthers.end() )
3251 anOthers.erase( foundIt );
3253 aToBeInSelected.insert( anEntry );
3256 aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() );
3258 // fill the CORBA arrays with values from sets
3260 theSelectedEntries.length( aSelected.size() );
3261 for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ )
3262 theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() );
3263 theParentEntries.length( aParents.size() );
3264 for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ )
3265 theParentEntries[i] = CORBA::string_dup( (*it).c_str() );
3266 theSubEntries.length( aChildren.size() );
3267 for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ )
3268 theSubEntries[i] = CORBA::string_dup( (*it).c_str() );
3269 theOtherEntries.length( anOthers.size() );
3270 for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ )
3271 theOtherEntries[i] = CORBA::string_dup( (*it).c_str() );
3275 //==============================================================================
3276 // function : includeParentDependencies
3278 //==============================================================================
3279 void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj,
3280 std::set<std::string>& aSelected,
3281 std::set<std::string>& aParents,
3282 std::set<std::string>& aChildren,
3283 std::set<std::string>& anOthers)
3285 std::string anEntry = geomObj->GetEntry();
3286 if ( aSelected.count( anEntry ) == 0 ) {
3287 aParents.insert( anEntry );
3288 std::set<std::string>::iterator it;
3289 it = aChildren.find( anEntry );
3290 if ( it != aChildren.end() )
3291 aChildren.erase( it );
3292 it = anOthers.find( anEntry );
3293 if ( it != anOthers.end() )
3294 anOthers.erase( it );
3296 // get dependencies for current object in the tree
3297 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3298 if( depList->length() == 0 )
3300 // go through dependencies of current object to check whether it depends on the given object
3301 std::string aDepEntry;
3302 for( CORBA::ULong i = 0; i < depList->length(); i++ ) {
3303 aDepEntry = depList[i]->GetEntry();
3304 if ( depList[i]->_is_nil() ||
3305 aDepEntry == anEntry || // skip self-depending
3306 aSelected.count( aDepEntry ) > 0 || // skip selected objects
3307 aParents.count( aDepEntry ) > 0 // skip already processed objects
3310 includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers );
3314 //==============================================================================
3315 // function : includeSubObjects
3317 //==============================================================================
3318 void GEOM_Gen_i::includeSubObjects(const std::string& aSelectedEntry,
3319 std::set<std::string>& aSelected,
3320 std::set<std::string>& aParents,
3321 std::set<std::string>& aChildren,
3322 std::set<std::string>& anOthers)
3324 std::set<std::string>::iterator foundIt;
3325 Handle(::GEOM_BaseObject) handle_object = _impl->GetObject(aSelectedEntry.c_str(), false);
3326 if ( handle_object.IsNull() )
3329 Handle(::GEOM_Function) aShapeFun = handle_object->GetFunction(1);
3330 if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() )
3333 const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences();
3334 if ( aListEntries.IsEmpty() )
3337 TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries);
3338 for ( ; anIt.More(); anIt.Next() ) {
3339 TCollection_ExtendedString aSubEntry = anIt.Value();
3340 Standard_Integer aStrLen = aSubEntry.LengthOfCString();
3341 char* aSubEntryStr = new char[aStrLen+1];
3342 aSubEntry.ToUTF8CString( aSubEntryStr );
3343 foundIt = aParents.find( aSubEntryStr );
3344 if ( foundIt == aParents.end() ) { // add to sub-objects if it is not in parents list
3345 foundIt = aSelected.find( aSubEntryStr );
3346 if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list
3347 aChildren.insert( aSubEntryStr );
3348 foundIt = anOthers.find( aSubEntryStr );
3349 if ( foundIt != anOthers.end() )
3350 anOthers.erase( foundIt );
3353 includeSubObjects( aSubEntryStr, aSelected, aParents, aChildren, anOthers );
3356 //=====================================================================================
3358 //=====================================================================================
3363 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
3367 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
3368 PortableServer::POA_ptr poa,
3369 PortableServer::ObjectId* contId,
3370 const char* instanceName,
3371 const char* interfaceName)
3373 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
3374 return myGEOM_Gen_i->getId();