1 // Copyright (C) 2007-2016 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 CORBA::string_dup(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_NAMESPACE(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 = aStudy->FindComponent("GEOM");
230 if (aFather->_is_nil()) {
231 aFather = aStudyBuilder->NewComponent("GEOM");
232 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
233 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
234 aName->SetValue("Geometry");
236 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
237 SALOMEDS::AttributePixMap_var aPixMap=SALOMEDS::AttributePixMap::_narrow(anAttr);
238 aPixMap->SetPixMap("ICON_OBJBROWSER_Geometry");
239 aPixMap->UnRegister();
240 aStudyBuilder->DefineComponentInstance(aFather, (GEOM::GEOM_Gen_var)GEOM_Gen::_this());
241 // add component to the use case tree
242 // (to support tree representation customization and drag-n-drop)
243 useCaseBuilder->SetRootCurrent();
244 useCaseBuilder->Append( aFather ); // component object is added as the top level item
246 if (aFather->_is_nil()) return aResultSO;
248 if (CORBA::is_nil(theSObject)) {
249 aResultSO = aStudyBuilder->NewObject(aFather);
251 if (!theSObject->ReferencedObject(aResultSO))
252 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
253 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
255 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
256 aResultSO->SetAttrString("AttributeIOR",aGeomObjIOR);
258 TCollection_AsciiString anObjectName, aNamePrefix("Shape_");
259 CORBA::Long mytype=aBaseObj->GetType();
261 // BEGIN: try to find existed name for current shape
262 if ( !aShape->_is_nil() && mytype != GEOM_GROUP)
264 // recieve current TopoDS shape
265 CORBA::String_var entry = aShape->GetEntry();
266 HANDLE_NAMESPACE(GEOM_Object) aGShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
267 ( _impl->GetObject( entry ));
268 TopoDS_Shape TopoSh = aGShape->GetValue();
269 // find label of main shape
270 GEOM::GEOM_Object_var aMainSh = aShape;
271 while( !aMainSh->IsMainShape() ) {
272 aMainSh = aMainSh->GetMainShape();
274 entry = aMainSh->GetEntry();
275 HANDLE_NAMESPACE(GEOM_BaseObject) anObj = _impl->GetObject( entry );
276 TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
278 // check all named shapes using iterator
279 TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
281 for (; anIt.More() && anObjectName.IsEmpty(); anIt.Next()) {
282 Handle(TNaming_NamedShape) anAttr =
283 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
284 if (anAttr.IsNull()) continue;
285 TopoDS_Shape S = anAttr->Get();
286 if (S.IsEqual(TopoSh)) {
287 TDF_Label L = anAttr->Label();
288 Handle(TDataStd_Name) aName;
289 if (L.FindAttribute(TDataStd_Name::GetID(), aName))
290 anObjectName = aName->Get();
294 // END: try to find existed name for current shape
296 if ( mytype == GEOM_GROUP ) {
297 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations();
298 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape )) {
300 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_PNT" );
301 aNamePrefix = "Group_Of_Vertices_";
304 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_EDGE");
305 aNamePrefix = "Group_Of_Edges_";
308 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_FACE");
309 aNamePrefix = "Group_Of_Faces_";
312 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_GROUP_SOLID");
313 aNamePrefix = "Group_Of_Solids_";
316 } else if ( mytype == GEOM_MARKER ) {
317 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_LCS");
318 aNamePrefix = "LocalCS_";
319 } else if ( mytype >= USER_TYPE_EX ) {
321 sprintf( buf, "%d", aBaseObj->GetType() );
322 GEOM::CreationInformationSeq_var infoSeq = aBaseObj->GetCreationInformation();
324 for ( size_t j = 0; j < infoSeq->length(); ++j )
325 for ( size_t i = 0; i < infoSeq[j].params.length(); ++i ) {
326 std::string param_name = infoSeq[j].params[i].name.in();
327 std::string param_value = infoSeq[j].params[i].value.in();
328 if( param_name == PLUGIN_NAME) {
333 if(plgId.length() > 0 ) {
336 plgId +="ICON_OBJBROWSER_";
338 aResultSO->SetAttrString("AttributePixMap",plgId.c_str());
339 } else if ( mytype > USER_TYPE ) {
341 sprintf( buf, "%d", aBaseObj->GetType() );
342 std::string advId = "ICON_OBJBROWSER_ADVANCED_"; advId += buf;
343 aResultSO->SetAttrString("AttributePixMap",advId.c_str());
344 aNamePrefix = "Advanced_";
345 } else if ( mytype == GEOM_FIELD ) {
346 aNamePrefix = "Field_";
347 GEOM::GEOM_Field_var aField = GEOM::GEOM_Field::_narrow(theObject);
348 if ( !aField->_is_nil() )
349 switch( aField->GetDimension() ) {
351 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_PNT" ); break;
353 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_EDGE"); break;
355 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_FACE"); break;
357 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID"); break;
359 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FIELD_SOLID");
361 } else if ( mytype == GEOM_FIELD_STEP ) {
362 aNamePrefix = "Step_";
363 } else if ( !aShape->_is_nil() ) {
364 GEOM::shape_type myshapetype=aShape->GetShapeType();
365 if ( myshapetype == GEOM::COMPOUND ) {
366 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPOUND" );
367 aNamePrefix = "Compound_";
368 } else if ( myshapetype == GEOM::COMPSOLID ) {
369 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_COMPSOLID");
370 aNamePrefix = "Compsolid_";
371 } else if ( myshapetype == GEOM::SOLID ) {
372 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SOLID");
373 aNamePrefix = "Solid_";
374 } else if ( myshapetype == GEOM::SHELL ) {
375 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_SHELL");
376 aNamePrefix = "Shell_";
377 } else if ( myshapetype == GEOM::FACE ) {
378 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_FACE");
379 aNamePrefix = "Face_";
380 } else if ( myshapetype == GEOM::WIRE ) {
381 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_WIRE");
382 aNamePrefix = "Wire_";
383 } else if ( myshapetype == GEOM::EDGE ) {
384 aResultSO->SetAttrString("AttributePixMap", "ICON_OBJBROWSER_EDGE");
385 aNamePrefix = "Edge_";
386 } else if ( myshapetype == GEOM::VERTEX ) {
387 aResultSO->SetAttrString("AttributePixMap","ICON_OBJBROWSER_VERTEX" );
388 aNamePrefix = "Vertex_";
391 if ( anObjectName.IsEmpty() )
393 //if (strlen(theName) == 0) aNamePrefix += TCollection_AsciiString(aResultSO->Tag());
394 //else anObjectName = TCollection_AsciiString(CORBA::string_dup(theName));
396 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
397 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
398 // of objects in the study, but compute a number of objects with the same prefix
399 // and build a new name as Prefix_N+1
400 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
401 int i = 0; // (WITH EMPTY NEW NAME)
402 SALOMEDS::SObject_var obj;
404 anObjectName = aNamePrefix + TCollection_AsciiString(++i);
405 obj = aStudy->FindObject( anObjectName.ToCString() );
407 while ( !obj->_is_nil() );
409 else { // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
410 anObjectName = theName;
414 //Set the study entry as a name of the published GEOM_Object
415 CORBA::String_var anID = aResultSO->GetID();
416 aBaseObj->SetStudyEntry(anID.in());
418 //Set a name of the added shape
419 aResultSO->SetAttrString("AttributeName",anObjectName.ToCString());
421 //Set NoteBook variables used in the object creation
422 TCollection_AsciiString aVars;
423 CORBA::String_var aString=aBaseObj->GetParameters();
424 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aString);
425 for(int i = 0, n = aSections->length(); i < n; i++) {
426 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
427 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
428 if(aStudy->IsVariable(aListOfVars[j].in()))
429 aVars += aListOfVars[j].in();
436 aResultSO->SetAttrString("AttributeString",aVars.ToCString());
438 aFather->UnRegister();
440 //Set a name of the GEOM object
441 aBaseObj->SetName(anObjectName.ToCString());
443 // add object to the use case tree
444 // (to support tree representation customization and drag-n-drop)
445 useCaseBuilder->AppendTo( aResultSO->GetFather(), aResultSO );
447 return aResultSO._retn();
450 //============================================================================
451 // function : CreateAndPublishGroup
452 // purpose : auxilary for PublishNamedShapesInStudy
453 //============================================================================
454 void GEOM_Gen_i::CreateAndPublishGroup(GEOM::GEOM_Object_var theMainShape,
455 const TopTools_IndexedMapOfShape& anIndices,
456 const TopTools_SequenceOfShape& SeqS,
457 const TColStd_SequenceOfAsciiString& SeqN,
458 const Standard_CString& GrName,
459 GEOM::ListOfGO_var aResList)
461 CORBA::String_var entry = theMainShape->GetEntry();
462 //HANDLE_NAMESPACE(GEOM_Object) aMainShape = _impl->GetObject(entry);
463 Handle(TColStd_HArray1OfInteger) anArray;
464 if(SeqS.Length()>0) {
466 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations();
467 GEOM::GEOM_Object_wrap GrObj = GOp->CreateGroup( theMainShape, SeqS(1).ShapeType() );
468 AddInStudy(GrObj, GrName, theMainShape._retn());
469 //CORBA::String_var GrEntry = GrObj->GetEntry();
470 //HANDLE_NAMESPACE(GEOM_Object) HGrObj = _impl->GetObject(GrEntry);
472 //HANDLE_NAMESPACE(GEOM_Object) anObj;
473 for(int i=1; i<=SeqS.Length(); i++) {
474 TopoDS_Shape aValue = SeqS.Value(i);
475 //anArray = new TColStd_HArray1OfInteger(1,1);
476 Standard_Integer anIndex = anIndices.FindIndex(aValue);
477 //anArray->SetValue(1, anIndex);
478 GOp->AddObject(GrObj,anIndex);
479 //anObj = GEOM_Engine::GetEngine()->AddObject(GEOM_SUBSHAPE);
480 //if (anObj.IsNull()) continue;
481 //HANDLE_NAMESPACE(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
482 //if (aFunction.IsNull()) continue;
483 //GEOM_ISubShape aSSI(aFunction);
484 //aSSI.SetMainShape(aMainShape->GetLastFunction());
485 //aSSI.SetIndices(anArray);
486 //aFunction->SetValue(aValue);
487 //GOp->UnionIDs(GrObj, anIndex);
488 //SALOMEDS::SObject_var aResultSO;
489 //TCollection_AsciiString anEntry;
490 //TDF_Tool::Entry(anObj->GetEntry(),anEntry);
491 //GEOM::GEOM_Object_var aGObj = GetObject(anEntry.ToCString());
492 //AddInStudy(aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
498 //============================================================================
499 // function : PublishNamedShapesInStudy
501 //============================================================================
502 GEOM::ListOfGO* GEOM_Gen_i::
503 PublishNamedShapesInStudy(//SALOMEDS::SObject_ptr theSObject,
504 CORBA::Object_ptr theObject)
506 //Unexpect aCatch(SALOME_SalomeException);
507 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
509 //CORBA::Object_var theObject = theSObject->GetObject();
510 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
511 if(theMainShape->_is_nil()) return aResList._retn();
513 CORBA::String_var entry = theMainShape->GetEntry();
514 HANDLE_NAMESPACE(GEOM_Object) aMainShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
515 ( _impl->GetObject( entry ));
516 if (aMainShape.IsNull()) return aResList._retn();
517 TopoDS_Shape MainSh = aMainShape->GetValue();
519 TDF_Label aMainLbl = aMainShape->GetEntry();
520 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
521 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
522 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
523 for(; anIt.More(); anIt.Next()) {
524 Handle(TNaming_NamedShape) anAttr =
525 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
526 if(anAttr.IsNull()) continue;
527 TopoDS_Shape S = anAttr->Get();
528 TDF_Label L = anAttr->Label();
529 //if(S.IsEqual(MainSh)) continue;
530 Handle(TDataStd_Name) aName;
531 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
532 TCollection_ExtendedString EName = aName->Get();
533 if(S.ShapeType()==TopAbs_SOLID) {
535 SolidSeqN.Append(aName->Get());
537 else if(S.ShapeType()==TopAbs_FACE) {
539 FaceSeqN.Append(aName->Get());
541 else if(S.ShapeType()==TopAbs_EDGE) {
543 EdgeSeqN.Append(aName->Get());
545 else if(S.ShapeType()==TopAbs_VERTEX) {
547 VertSeqN.Append(aName->Get());
552 TopTools_IndexedMapOfShape anIndices;
553 TopExp::MapShapes(MainSh, anIndices);
555 CreateAndPublishGroup(theMainShape, anIndices, SolidSeqS, SolidSeqN,
556 "Group_Of_Named_Solids", aResList);
558 CreateAndPublishGroup(theMainShape, anIndices, FaceSeqS, FaceSeqN,
559 "Group_Of_Named_Faces", aResList);
561 CreateAndPublishGroup(theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
562 "Group_Of_Named_Edges", aResList);
564 CreateAndPublishGroup(theMainShape, anIndices, VertSeqS, VertSeqN,
565 "Group_Of_Named_Vertices", aResList);
567 return aResList._retn();
571 //============================================================================
573 // purpose : save OCAF/Geom document
574 //============================================================================
575 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
578 SALOMEDS::TMPFile_var aStreamFile;
579 // Get a temporary directory to store a file
580 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
582 // OCCT BUG: cannot save a document (in current folder)
583 // if directory name is empty
584 if (aTmpDir.size() == 0) {
592 // Create a list to store names of created files
593 SALOMEDS_Tool::ListOfFiles aSeq;
595 // Prepare a file name to open
596 TCollection_AsciiString aNameWithExt("");
598 aNameWithExt = TCollection_AsciiString( (char*)(SALOMEDS_Tool::GetNameFromPath(
599 Kernel_Utils::encode(getStudyServant()->URL())).c_str()));
600 #if OCC_VERSION_MAJOR > 6
601 aNameWithExt += TCollection_AsciiString("_GEOM.cbf");
603 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
605 aSeq.push_back(CORBA::string_dup(aNameWithExt.ToCString()));
606 // Build a full file name of temporary file
607 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
608 // Save GEOM component in this file
609 _impl->Save((char*) aFullName.ToCString());
610 // Conver a file to the byte stream
611 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq, isMultiFile);
612 // Remove the created file and tmp directory
613 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
615 // Return the created byte stream
616 return aStreamFile._retn();
620 //============================================================================
621 // function : SaveASCII()
623 //============================================================================
624 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
627 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
628 return aStreamFile._retn();
632 //============================================================================
635 //============================================================================
636 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
637 const SALOMEDS::TMPFile& theStream,
641 if (theStream.length() <= 9) {
642 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
646 // Get a temporary directory for a file
647 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
649 // OCCT BUG: cannot load a document (from current folder)
650 // if directory name is empty
651 if (aTmpDir.size() == 0) {
659 // Conver the byte stream theStream to a file and place it in tmp directory
660 SALOMEDS_Tool::ListOfFiles aSeq =
661 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
663 // Prepare a file name to open
664 TCollection_AsciiString aNameWithExt("");
665 SALOMEDS::Study_var study = getStudyServant();
667 #if OCC_VERSION_MAJOR > 6
668 // Get the file name.
670 int aLength = aSeq.size();
671 const char *aGeomSgd = "_GEOM.sgd";
672 const char *aGeomcbf = "_GEOM.cbf";
674 for(i = 0; i < aLength; i++) {
675 std::string aName(aSeq[i]);
677 if (aName.rfind(aGeomSgd) != std::string::npos ||
678 aName.rfind(aGeomcbf) != std::string::npos) {
679 aNameWithExt = aName.c_str();
685 CORBA::String_var url = study->URL();
686 aNameWithExt = (char*)SALOMEDS_Tool::GetNameFromPath(url.in()).c_str();
689 aNameWithExt += "_GEOM.sgd";
692 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
695 if (!_impl->Load((char*) aFullName.ToCString())) return false;
697 // Remove the created file and tmp directory
698 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq, true);
700 // creation of tree nodes for all data objects in the study
701 // to support tree representation customization and drag-n-drop:
702 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
703 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
704 useCaseBuilder->SetRootCurrent();
705 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
708 SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
709 for ( it->InitEx(true); it->More(); it->Next() ) {
710 if ( !useCaseBuilder->IsUseCaseNode( it->Value() ) ) {
711 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
719 //============================================================================
720 // function : LoadASCII()
722 //============================================================================
723 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
724 const SALOMEDS::TMPFile& theStream,
727 return Load(theComponent, theStream, theURL, isMultiFile);
731 //============================================================================
732 // function : Close()
734 //============================================================================
735 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
740 //============================================================================
741 // function : CanCopy()
743 //============================================================================
744 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
745 // Try to retrieve known by Geometry component GEOM_Object by given IOR
746 SALOMEDS::GenericAttribute_var anAttr;
747 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
749 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
751 CORBA::String_var aString=anIOR->Value();
753 CORBA::Object_var anObj = _orb->string_to_object(aString);
754 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(anObj);
755 // If the object is null one it can't be copied: return false
756 if (anObject->_is_nil()) return false;
760 //============================================================================
761 // function : CopyFrom()
763 //============================================================================
764 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
766 // Declare a sequence of the byte to store the copied object
767 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
769 // Try to get GEOM_Object object by given SObject
770 SALOMEDS::GenericAttribute_var anAttr;
771 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
772 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
773 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
774 if (anObject->_is_nil()) return aStreamFile._retn();
776 aStreamFile = anObject->GetShapeStream();
778 // Assign an ID the type of GEOM_Object
779 theObjectID = anObject->GetType();
781 // Return created TMPFile
782 return aStreamFile._retn();
785 //============================================================================
786 // function : CanPaste()
788 //============================================================================
789 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
790 // The Geometry component can paste only objects copied by Geometry component
791 // and with the object type = 1
792 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
796 //============================================================================
797 // function : PasteInto()
799 //============================================================================
800 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
801 CORBA::Long theObjectID,
802 SALOMEDS::SObject_ptr theObject) {
803 // Find the current Study and StudyBuilder
804 SALOMEDS::Study_var aStudy = getStudyServant();
805 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
806 SALOMEDS::UseCaseBuilder_var anUseCaseBuilder = aStudy->GetUseCaseBuilder();
807 SALOMEDS::SObject_var aNewSO;
808 // Retrieve a TopoDS_Shape from byte stream
809 TopoDS_Shape aTopology;
810 std::istringstream aStreamedBrep((char*) &theStream[0]);
811 BRep_Builder aBuilder;
813 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
814 } catch (Standard_Failure) {
815 return aNewSO._retn();
818 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
819 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
820 aNewSO = aStudyBuilder->NewObject(theObject);
821 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
824 //Create a new GEOM_Object
825 HANDLE_NAMESPACE(GEOM_Object) anObj = _impl->AddObject(theObjectID);
826 HANDLE_NAMESPACE(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
827 aFunction->SetValue(aTopology);
829 TCollection_AsciiString anEntry;
830 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
831 GEOM::GEOM_BaseObject_var obj = GetObject(anEntry.ToCString());
833 //Set the study entry of the published GEOM_Object
834 obj->SetStudyEntry(aNewSO->GetID());
836 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
837 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
838 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
839 CORBA::String_var objStr = _orb->object_to_string(obj);
840 anIOR->SetValue(objStr.in());
843 // add object to the use case tree
844 // (to support tree representation customization and drag-n-drop)
845 anUseCaseBuilder->AppendTo( aNewSO->GetFather(), aNewSO );
847 // Return the created in the Study SObject
848 return aNewSO._retn();
851 //============================================================================
852 // function : ComponentDataType()
854 //============================================================================
855 char* GEOM_Gen_i::ComponentDataType()
857 return CORBA::string_dup("GEOM");
860 //============================================================================
861 // function : AddInStudy
863 //============================================================================
864 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (GEOM::GEOM_BaseObject_ptr theObject,
866 GEOM::GEOM_BaseObject_ptr theFather)
868 SALOMEDS::SObject_var aResultSO;
869 SALOMEDS::Study_var aStudy = getStudyServant();
870 if(theObject->_is_nil() || aStudy->_is_nil()) return aResultSO;
872 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
873 CORBA::String_var IOR;
875 if(!theFather->_is_nil()) {
876 IOR = _orb->object_to_string(theFather);
877 SALOMEDS::SObject_wrap aFatherSO = aStudy->FindObjectIOR(IOR.in());
878 if(aFatherSO->_is_nil()) return aResultSO._retn();
879 aResultSO = aStudyBuilder->NewObject(aFatherSO);
880 //aStudyBuilder->Addreference(aResultSO, aResultSO);
883 aResultSO = PublishInStudy(aResultSO, theObject, theName);
884 if(aResultSO->_is_nil()) return aResultSO._retn();
886 GEOM::ListOfGBO_var aList = theObject->GetDependency();
887 Standard_Integer aLength = aList->length();
888 if(aLength < 1) return aResultSO._retn();
890 //Publish the arguments
891 TCollection_AsciiString aPrevID; // to avoid multiple references to same object
892 for(Standard_Integer i = 0; i< aLength; i++) {
893 GEOM::GEOM_BaseObject_var anObject = aList[i];
894 if(anObject->_is_nil()) continue;
895 IOR = _orb->object_to_string(anObject);
896 SALOMEDS::SObject_wrap aSO = aStudy->FindObjectIOR(IOR.in());
897 if(aSO->_is_nil()) continue;
898 CORBA::String_var anID = aSO->GetID();
899 if ( aPrevID == anID.in() ) continue;
901 SALOMEDS::SObject_wrap aSubSO = aStudyBuilder->NewObject(aResultSO);
902 aStudyBuilder->Addreference(aSubSO, aSO);
903 aStudy->GetUseCaseBuilder()->AppendTo( aResultSO, aSubSO );
906 return aResultSO._retn();
909 //============================================================================
910 // function : RestoreSubShapesO
911 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
912 // To be used from python scripts out of geompy.addToStudy (non-default usage)
913 //============================================================================
914 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesO (GEOM::GEOM_Object_ptr theObject,
915 const GEOM::ListOfGO& theArgs,
916 GEOM::find_shape_method theFindMethod,
917 CORBA::Boolean theInheritFirstArg,
918 CORBA::Boolean theAddPrefix)
920 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
921 SALOMEDS::Study_var aStudy = getStudyServant();
922 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject))
923 return aParts._retn();
925 // find SObject in the study if it is already published
926 CORBA::String_var anIORo = _orb->object_to_string(theObject);
927 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(anIORo.in());
928 //PTv, IMP 0020001, The salome object <aSO>
929 // is not obligatory in case of invokation from script
930 // if (CORBA::is_nil(aSO))
931 // return aParts._retn();
933 aParts = RestoreSubShapes(theObject, aSO, theArgs,
934 theFindMethod, theInheritFirstArg, theAddPrefix);
935 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
936 return aParts._retn();
939 //============================================================================
940 // function : RestoreGivenSubShapesO
941 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
942 // To be used from python scripts, generated by Dump Python.
943 //============================================================================
944 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesO (GEOM::GEOM_Object_ptr theObject,
945 const GEOM::ListOfGO& theArgs,
946 GEOM::find_shape_method theFindMethod,
947 CORBA::Boolean theInheritFirstArg,
948 CORBA::Boolean theAddPrefix)
950 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
951 if (CORBA::is_nil(getStudyServant()) || CORBA::is_nil(theObject))
952 return aParts._retn();
954 // find SObject in the study if it is already published
955 CORBA::String_var anIORo = _orb->object_to_string(theObject);
956 SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectIOR(anIORo.in());
957 //PTv, IMP 0020001, The salome object <aSO>
958 // is not obligatory in case of invokation from script
959 // if (CORBA::is_nil(aSO))
960 // return aParts._retn();
962 aParts = RestoreGivenSubShapes(theObject, aSO, theArgs,
963 theFindMethod, theInheritFirstArg, theAddPrefix);
964 if (!CORBA::is_nil(aSO)) aSO->UnRegister();
965 return aParts._retn();
968 //============================================================================
969 // function : RestoreSubShapesSO
970 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
971 // To be used from GUI and from geompy.addToStudy
972 //============================================================================
973 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::SObject_ptr theSObject,
974 const GEOM::ListOfGO& theArgs,
975 GEOM::find_shape_method theFindMethod,
976 CORBA::Boolean theInheritFirstArg,
977 CORBA::Boolean theAddPrefix)
979 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
980 if (CORBA::is_nil(getStudyServant()) || CORBA::is_nil(theSObject))
981 return aParts._retn();
983 SALOMEDS::GenericAttribute_var anAttr;
984 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
985 return aParts._retn();
987 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
988 CORBA::String_var anIORso = anAttrIOR->Value();
990 // get Object from SObject
991 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
992 if (CORBA::is_nil(anO))
993 return aParts._retn();
995 aParts = RestoreSubShapes(anO, theSObject, theArgs,
996 theFindMethod, theInheritFirstArg, theAddPrefix);
997 return aParts._retn();
1000 //============================================================================
1001 // function : addToListOfGO
1002 // purpose : static local function
1003 //============================================================================
1004 static void addToListOfGO( GEOM::GEOM_Object_ptr theObject,
1005 GEOM::ListOfGO& theList )
1007 const int oldLen = theList.length();
1008 theList.length(oldLen + 1);
1009 theList[ oldLen ] = GEOM::GEOM_Object::_duplicate( theObject );
1012 //============================================================================
1013 // function : addToListOfGO
1014 // purpose : static local function
1015 //============================================================================
1016 static void addToListOfGO( const GEOM::ListOfGO& theSrcList,
1017 GEOM::ListOfGO& theTrgList )
1019 const int oldLen = theTrgList.length();
1020 const int srcLen = theSrcList.length();
1021 theTrgList.length(oldLen + srcLen);
1022 for( int i = 0; i < srcLen; i++ )
1023 theTrgList[ oldLen + i ] = GEOM::GEOM_Object::_duplicate( theSrcList[ i ] );
1026 //============================================================================
1027 // function : RestoreSubShapes
1028 // purpose : Private method. Works only if both theObject and theSObject
1029 // are defined, and does not check, if they correspond to each other.
1030 //============================================================================
1031 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(GEOM::GEOM_Object_ptr theObject,
1032 SALOMEDS::SObject_ptr theSObject,
1033 const GEOM::ListOfGO& theArgs,
1034 GEOM::find_shape_method theFindMethod,
1035 CORBA::Boolean theInheritFirstArg,
1036 CORBA::Boolean theAddPrefix)
1038 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1039 SALOMEDS::Study_var aStudy = getStudyServant();
1040 //PTv, IMP 0020001, The salome object <theSObject>
1041 // is not obligatory in case of invokation from script
1042 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1043 return aParts._retn();
1045 // For Dump Python (mantis issue 0020768)
1046 GEOM::ListOfGO_var anOutArgs = new GEOM::ListOfGO;
1048 // Arguments to be published
1049 GEOM::ListOfGO_var aList;
1051 // If theArgs list is empty, we try to publish all arguments,
1052 // otherwise publish only passed args
1053 Standard_Integer nbArgsActual = -1; // -1 means unknown
1054 Standard_Integer aLength = theArgs.length();
1056 aList = new GEOM::ListOfGO;
1057 aList->length(aLength);
1058 for (int i = 0; i < aLength; i++) {
1059 aList[i] = GEOM::GEOM_Object::_duplicate( theArgs[i] );
1063 // Get all arguments
1064 GEOM::ListOfGBO_var boList = theObject->GetDependency();
1065 aLength = boList->length();
1066 aList = new GEOM::ListOfGO;
1067 aList->length(aLength);
1068 for (int i = 0; i < aLength; i++)
1069 aList[i] = GEOM::GEOM_Object::_narrow( boList[i] );
1070 nbArgsActual = aLength;
1074 return aParts._retn();
1076 if (theInheritFirstArg || (nbArgsActual == 1)) {
1077 // Do not publish argument's reflection,
1078 // but only reconstruct its published sub-shapes
1080 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1081 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1083 // remember restored objects for Python Dump
1084 addToListOfGO(aList[0], anOutArgs);
1086 aParts = RestoreSubShapesOneLevel(anArgSO, theSObject, theObject,
1087 anOutArgs, theFindMethod, theAddPrefix);
1089 // set the color of the transformed shape to the color of initial shape
1090 theObject->SetColor(aList[0]->GetColor());
1092 if (theObject->GetShapeType() == GEOM::VERTEX) {
1093 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1094 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1095 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1097 if (!CORBA::is_nil(anArgSO))
1098 anArgSO->UnRegister();
1101 // Get interface, containing method, which we will use to reconstruct sub-shapes
1102 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1103 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1104 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1106 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1107 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1109 // Reconstruct arguments and tree of sub-shapes of the arguments
1110 CORBA::String_var anIOR;
1111 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1112 for (Standard_Integer i = 0; i < aLength; i++)
1114 GEOM::GEOM_Object_var anArgO = aList[i];
1115 if (!CORBA::is_nil(anArgO)) {
1116 anIOR = _orb->object_to_string(anArgO);
1117 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1118 TCollection_AsciiString anArgName;
1119 if (CORBA::is_nil(anArgSO)) {
1121 anArgName += TCollection_AsciiString(i);
1124 anArgName = anArgSO->GetName();
1127 // Find a sub-shape of theObject in place of the argument
1128 GEOM::GEOM_Object_var aSubO;
1129 switch (theFindMethod) {
1130 case GEOM::FSM_GetInPlace:
1133 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1136 case GEOM::FSM_MultiTransformed:
1138 // Only for Multi-transformations
1139 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1140 if (!CORBA::is_nil(anArgOTrsf)) {
1141 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1142 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1143 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1144 anArgOTrsfFun->SetDescription("");
1145 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1148 HANDLE_NAMESPACE(GEOM_Function) anOFun = theObject->GetLastFunction();
1149 if (!anOFun.IsNull()) {
1150 CORBA::String_var entryArg = anArgO->GetEntry();
1151 HANDLE_NAMESPACE(GEOM_Object) anArgOImpl = _impl->GetObject(entryArg);
1152 if (!anArgOImpl.IsNull()) {
1153 TopoDS_Shape anArgOShape = anArgOImpl->GetValue();
1154 TopoDS_Shape aMultiArgShape;
1155 //GEOM::GEOM_Object_var anArgOMulti; // ???
1156 switch (anOFun->GetType()) {
1159 GEOMImpl_ITranslate aTI (anOFun);
1160 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI);
1161 //anArgOMulti = aTrsfOpSv->Translate1D(anArgO, , , );
1166 GEOMImpl_ITranslate aTI (anOFun);
1167 aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1172 GEOMImpl_IRotate aTI (anOFun);
1173 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1178 GEOMImpl_IRotate aTI (anOFun);
1179 //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI);
1185 GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO
1186 HANDLE_NAMESPACE(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction();
1187 anArgOMultiFun->SetDescription("");
1188 aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti);
1194 case GEOM::FSM_Transformed:
1196 // transformation, cannot use GetInPlace, operate with indices
1197 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1198 if (anIDs->length() > 1) {
1200 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1201 if (!CORBA::is_nil(aSubO))
1202 aGroupOp->UnionIDs(aSubO, anIDs);
1204 else if (anIDs->length() > 0) {
1206 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1210 case GEOM::FSM_GetSame:
1213 aSubO = aShapesOp->GetSame(theObject, anArgO);
1216 case GEOM::FSM_GetShapesOnShape:
1218 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1219 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1220 (short)GEOM::SOLID, GEOM::ST_ONIN);
1223 case GEOM::FSM_GetInPlaceByHistory:
1225 // Use GetInPlaceByHistory
1226 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1233 if (!CORBA::is_nil(aSubO)) {
1234 // remember restored objects for Python Dump
1235 addToListOfGO(anArgO, anOutArgs);
1237 // add to parts list
1238 addToListOfGO( aSubO, aParts );
1240 // Publish the sub-shape
1241 SALOMEDS::SObject_var aSubSO;
1242 if (!CORBA::is_nil(theSObject)) {
1243 TCollection_AsciiString aSubName;
1247 aSubName += anArgName;
1248 aSubSO = aStudyBuilder->NewObject(theSObject);
1249 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1251 aSubO->SetColor(anArgO->GetColor());
1253 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1254 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1255 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1256 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1260 if (!CORBA::is_nil(anArgSO)) {
1261 // Restore published sub-shapes of the argument
1262 GEOM::ListOfGO_var aSubParts;
1263 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1264 // pass theObject, because only it has the history
1265 aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO,
1266 theObject, anOutArgs, theFindMethod, theAddPrefix);
1268 aSubParts = RestoreSubShapesOneLevel(anArgSO, aSubSO,
1269 aSubO, anOutArgs, theFindMethod, theAddPrefix);
1270 // add to parts list
1271 addToListOfGO( aSubParts, aParts );
1274 else { // GetInPlace failed, try to build from published parts
1275 if (!CORBA::is_nil(anArgSO)) {
1276 SALOMEDS::SObject_var aSubSO;
1277 if (!CORBA::is_nil(theSObject))
1278 aSubSO = aStudyBuilder->NewObject(theSObject);
1280 // Restore published sub-shapes of the argument
1281 GEOM::ListOfGO_var aSubParts =
1282 RestoreSubShapesOneLevel(anArgSO, aSubSO,
1283 theObject, anOutArgs, theFindMethod, theAddPrefix);
1285 // add to parts list
1286 addToListOfGO( aSubParts, aParts );
1288 if (aSubParts->length() > 0) {
1289 // remember restored objects for Python Dump
1290 addToListOfGO(anArgO, anOutArgs);
1292 // try to build an argument from a set of its sub-shapes,
1293 // that published and will be reconstructed
1294 if (aSubParts->length() > 1) {
1295 aSubO = aShapesOp->MakeCompound(aSubParts);
1296 // add to parts list
1297 addToListOfGO( aSubO, aParts );
1300 aSubO = aSubParts[0];
1302 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1303 // Publish the sub-shape
1304 TCollection_AsciiString aSubName;
1306 aSubName = "from_parts_of_";
1308 aSubName += anArgName;
1309 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1311 aSubO->SetColor(anArgO->GetColor());
1313 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1314 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1315 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1316 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1320 else if (!CORBA::is_nil(aSubSO)) {
1321 // remove created aSubSO, because no parts have been found
1322 aStudyBuilder->RemoveObject(aSubSO);
1325 } // try to build from published parts
1326 if (!CORBA::is_nil(anArgSO))
1327 anArgSO->UnRegister();
1329 } // process arguments
1331 std::set<std::string> anObjEntryMap;
1332 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1334 int nb = aParts->length();
1335 aResParts->length(nb);
1338 HANDLE_NAMESPACE(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry());
1339 HANDLE_NAMESPACE(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1340 GEOM::TPythonDump pd (aFunction, true);
1343 for ( ; i < nb; i++ )
1345 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1346 if (CORBA::is_nil(anObj))
1348 char* anEntry = anObj->GetEntry();
1349 if (anObjEntryMap.count(anEntry))
1350 continue; // already treated
1351 anObjEntryMap.insert(anEntry);
1352 aResParts[nbRes++] = anObj;
1353 // clear python dump of object
1354 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry);
1355 HANDLE_NAMESPACE(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1356 if ( !anObjFun.IsNull() )
1357 anObjFun->SetDescription( "" );
1363 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1364 //i = 0; nb = theArgs.length(); j = 0;
1365 i = 0; nb = anOutArgs->length(); j = 0;
1366 for ( ; i < nb; i++ )
1368 //GEOM::GEOM_Object_var anObj = theArgs[ i ];
1369 GEOM::GEOM_Object_var anObj = anOutArgs[ i ];
1370 if (CORBA::is_nil(anObj))
1372 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry());
1378 pd <<"]" << ", " <<"GEOM.";
1379 switch (theFindMethod) {
1380 case GEOM::FSM_GetInPlace:
1381 pd << "FSM_GetInPlace"; break;
1382 case GEOM::FSM_MultiTransformed:
1383 pd << "FSM_MultiTransformed"; break;
1384 case GEOM::FSM_Transformed:
1385 pd << "FSM_Transformed"; break;
1386 case GEOM::FSM_GetSame:
1387 pd << "FSM_GetSame"; break;
1388 case GEOM::FSM_GetShapesOnShape:
1389 pd << "FSM_GetShapesOnShape"; break;
1390 case GEOM::FSM_GetInPlaceByHistory:
1392 pd << "FSM_GetInPlaceByHistory"; break;
1394 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1396 aResParts->length(nbRes);
1397 return aResParts._retn();
1400 //============================================================================
1401 // function : RestoreSubShapesOneLevel
1402 // purpose : Private method
1403 //============================================================================
1404 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO,
1405 SALOMEDS::SObject_ptr theNewSO,
1406 GEOM::GEOM_Object_ptr theNewO,
1407 GEOM::ListOfGO& theOutArgs,
1408 GEOM::find_shape_method theFindMethod,
1409 CORBA::Boolean theAddPrefix)
1412 SALOMEDS::Study_var aStudy = getStudyServant();
1413 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1414 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1415 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) ||
1416 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1417 return aParts._retn();
1419 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1421 // Get interface, containing method, which we will use to reconstruct sub-shapes
1422 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1423 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1424 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1426 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1427 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1429 // Reconstruct published sub-shapes
1430 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO);
1433 for (it->Init(); it->More(); it->Next()) {
1436 aParts->length(aLen);
1438 for (it->Init(); it->More(); it->Next()) {
1439 SALOMEDS::SObject_var anOldSubSO = it->Value();
1441 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1443 SALOMEDS::GenericAttribute_var anAttr;
1444 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1445 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1446 GEOM::GEOM_Object_var anOldSubO =
1447 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1448 if (!CORBA::is_nil(anOldSubO)) {
1449 // Find a sub-shape of theNewO in place of anOldSubO
1450 GEOM::GEOM_Object_var aNewSubO;
1451 switch (theFindMethod) {
1452 case GEOM::FSM_GetInPlace:
1455 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1458 case GEOM::FSM_MultiTransformed:
1460 // Only for Multi-transformations
1461 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
1462 if (!CORBA::is_nil(anArgOTrsf)) {
1463 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1464 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1465 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1466 anArgOTrsfFun->SetDescription("");
1467 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
1471 case GEOM::FSM_Transformed:
1473 // transformation, cannot use GetInPlace, operate with indices
1474 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1475 if (anIDs->length() > 1) {
1477 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1478 if (!CORBA::is_nil(aNewSubO))
1479 aGroupOp->UnionIDs(aNewSubO, anIDs);
1483 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1487 case GEOM::FSM_GetSame:
1490 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1493 case GEOM::FSM_GetShapesOnShape:
1495 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1496 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1497 (short)GEOM::SOLID, GEOM::ST_ONIN);
1500 case GEOM::FSM_GetInPlaceByHistory:
1502 // Use GetInPlaceByHistory
1503 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1510 if (!CORBA::is_nil(aNewSubO)) {
1511 // remember restored objects for Python Dump
1512 addToListOfGO(anOldSubO, theOutArgs);
1514 // add the part to the list
1515 aParts[i] = aNewSubO;
1517 // add to parts list
1518 addToListOfGO( aNewSubO, aNewParts );
1520 SALOMEDS::SObject_var aNewSubSO;
1521 if (!CORBA::is_nil(theNewSO)) {
1522 // Publish the sub-shape
1523 TCollection_AsciiString aSubName;
1527 aSubName += anArgName;
1528 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1529 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
1531 aNewSubO->SetColor(anOldSubO->GetColor());
1533 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1534 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1535 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1536 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1539 // Restore published sub-shapes of the argument
1540 GEOM::ListOfGO_var aSubParts;
1541 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1542 // pass the main shape as Object, because only it has the history
1543 aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1544 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1546 aSubParts = RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1547 aNewSubO, theOutArgs, theFindMethod, theAddPrefix);
1548 // add to parts list
1549 addToListOfGO( aSubParts, aNewParts );
1551 else { // GetInPlace failed, try to build from published parts
1552 SALOMEDS::SObject_var aNewSubSO;
1553 if (!CORBA::is_nil(theNewSO))
1554 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1556 // Restore published sub-shapes of the argument
1557 GEOM::ListOfGO_var aSubParts =
1558 RestoreSubShapesOneLevel(anOldSubSO, aNewSubSO,
1559 theNewO, theOutArgs, theFindMethod, theAddPrefix);
1560 // add to parts list
1561 addToListOfGO( aSubParts, aNewParts );
1563 if (aSubParts->length() > 0) {
1564 // remember restored objects for Python Dump
1565 addToListOfGO(anOldSubO, theOutArgs);
1567 // try to build an object from a set of its sub-shapes,
1568 // that published and will be reconstructed
1569 if (aSubParts->length() > 1) {
1570 aNewSubO = aShapesOp->MakeCompound(aSubParts);
1571 // add to parts list
1572 addToListOfGO( aNewSubO, aNewParts );
1575 aNewSubO = aSubParts[0];
1578 if (!CORBA::is_nil(aNewSubO)) {
1579 // add the part to the list
1580 aSubParts[i] = aNewSubO;
1583 // Publish the sub-shape
1584 if (!CORBA::is_nil(aNewSubSO)) {
1585 TCollection_AsciiString aSubName;
1587 aSubName = "from_parts_of_";
1589 aSubName += anArgName;
1590 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
1592 aNewSubO->SetColor(anOldSubO->GetColor());
1594 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
1595 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
1596 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
1597 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
1602 else if (!CORBA::is_nil(aNewSubSO)) {
1603 // remove created aSubSO, because no parts have been found
1604 aStudyBuilder->RemoveObject(aNewSubSO);
1606 } // try to build from published parts
1609 } // iterate on published sub-shapes
1612 // add to parts list
1613 addToListOfGO( aNewParts, aParts );
1614 return aParts._retn();
1617 //============================================================================
1618 // function : RestoreGivenSubShapes
1619 // purpose : Private method. Works only if both theObject and theSObject
1620 // are defined, and does not check, if they correspond to each other.
1621 // List theArgs in this case contains not only operation arguments,
1622 // but also all subshapes, which must be published.
1623 //============================================================================
1624 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(GEOM::GEOM_Object_ptr theObject,
1625 SALOMEDS::SObject_ptr theSObject,
1626 const GEOM::ListOfGO& theArgs,
1627 GEOM::find_shape_method theFindMethod,
1628 CORBA::Boolean theInheritFirstArg,
1629 CORBA::Boolean theAddPrefix)
1631 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1632 SALOMEDS::Study_var aStudy = getStudyServant();
1633 //PTv, IMP 0020001, The salome object <theSObject>
1634 // is not obligatory in case of invokation from script
1635 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theObject) /*|| CORBA::is_nil(theSObject)*/)
1636 return aParts._retn();
1638 // If theArgs list is empty, nothing to do
1639 Standard_Integer aLength = theArgs.length();
1641 return aParts._retn();
1643 // Get all arguments
1644 GEOM::ListOfGBO_var anOpArgsList = theObject->GetDependency();
1645 Standard_Integer nbArgsActual = anOpArgsList->length();
1647 // If anOpArgsList list is empty, nothing to do
1648 if (nbArgsActual == 0)
1649 return aParts._retn();
1651 // Entries of arguments and subshapes
1652 std::set<std::string> anArgs;
1653 for (int i = 0; i < aLength; i++) {
1654 CORBA::String_var anEntry = theArgs[i]->GetEntry();
1655 anArgs.insert(anEntry.in());
1658 // Arguments to be published
1659 // We try to publish all arguments, that are in theArgs list
1660 GEOM::ListOfGO_var aList = new GEOM::ListOfGO;
1661 aList->length(nbArgsActual);
1664 for (int j = 0; j < nbArgsActual; j++) {
1665 CORBA::String_var anEntry = anOpArgsList[j]->GetEntry();
1666 if (anArgs.count(anEntry.in())) {
1667 aList[k] = GEOM::GEOM_Object::_narrow(anOpArgsList[j]);
1672 //aList->length(nbArgsActual);
1674 if (nbArgsActual < 1)
1675 return aParts._retn();
1677 if (theInheritFirstArg || (nbArgsActual == 1)) {
1678 // Do not publish argument's reflection,
1679 // but only reconstruct its published sub-shapes
1681 CORBA::String_var anIOR = _orb->object_to_string(aList[0]);
1682 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1684 aParts = RestoreGivenSubShapesOneLevel(anArgSO, theSObject, theObject,
1685 anArgs, theFindMethod, theAddPrefix);
1687 // set the color of the transformed shape to the color of initial shape
1688 theObject->SetColor(aList[0]->GetColor());
1690 if (theObject->GetShapeType() == GEOM::VERTEX) {
1691 theObject->SetMarkerStd(aList[0]->GetMarkerType(), aList[0]->GetMarkerSize());
1692 if (aList[0]->GetMarkerType() == GEOM::MT_USER)
1693 theObject->SetMarkerTexture(aList[0]->GetMarkerTexture());
1696 anArgSO->UnRegister();
1699 // Get interface, containing method, which we will use to reconstruct sub-shapes
1700 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1701 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1702 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1704 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1705 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1707 // Reconstruct arguments and tree of sub-shapes of the arguments
1708 CORBA::String_var anIOR;
1709 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1710 for (Standard_Integer i = 0; i < nbArgsActual; i++)
1712 GEOM::GEOM_Object_var anArgO = aList[i];
1713 if (!CORBA::is_nil(anArgO)) {
1714 anIOR = _orb->object_to_string(anArgO);
1715 SALOMEDS::SObject_var anArgSO = aStudy->FindObjectIOR(anIOR.in());
1716 TCollection_AsciiString anArgName;
1717 if (CORBA::is_nil(anArgSO)) {
1719 anArgName += TCollection_AsciiString(i);
1722 anArgName = anArgSO->GetName();
1725 // Find a sub-shape of theObject in place of the argument
1726 GEOM::GEOM_Object_var aSubO;
1727 switch (theFindMethod) {
1728 case GEOM::FSM_GetInPlace:
1731 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
1734 case GEOM::FSM_MultiTransformed:
1736 // Only for Multi-transformations
1737 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anArgO, theObject);
1738 if (!CORBA::is_nil(anArgOTrsf)) {
1739 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
1740 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
1741 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
1742 anArgOTrsfFun->SetDescription("");
1743 aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf);
1747 case GEOM::FSM_Transformed:
1749 // transformation, cannot use GetInPlace, operate with indices
1750 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
1751 if (anIDs->length() > 1) {
1753 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
1754 if (!CORBA::is_nil(aSubO))
1755 aGroupOp->UnionIDs(aSubO, anIDs);
1757 else if (anIDs->length() > 0) {
1759 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
1763 case GEOM::FSM_GetSame:
1766 aSubO = aShapesOp->GetSame(theObject, anArgO);
1769 case GEOM::FSM_GetShapesOnShape:
1771 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1772 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
1773 (short)GEOM::SOLID, GEOM::ST_ONIN);
1776 case GEOM::FSM_GetInPlaceByHistory:
1778 // Use GetInPlaceByHistory
1779 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
1786 if (!CORBA::is_nil(aSubO)) {
1787 // add to parts list
1788 addToListOfGO( aSubO, aParts );
1790 // Publish the sub-shape
1791 SALOMEDS::SObject_var aSubSO;
1792 if (!CORBA::is_nil(theSObject)) {
1793 TCollection_AsciiString aSubName;
1797 aSubName += anArgName;
1798 aSubSO = aStudyBuilder->NewObject(theSObject);
1799 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1801 aSubO->SetColor(anArgO->GetColor());
1803 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1804 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1805 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1806 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1810 if (!CORBA::is_nil(anArgSO)) {
1811 // Restore published sub-shapes of the argument
1812 GEOM::ListOfGO_var aSubParts;
1813 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1814 // pass theObject, because only it has the history
1815 aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1816 theObject, anArgs, theFindMethod, theAddPrefix);
1818 aSubParts = RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1819 aSubO, anArgs, theFindMethod, theAddPrefix);
1820 // add to parts list
1821 addToListOfGO( aSubParts, aParts );
1824 else { // GetInPlace failed, try to build from published parts
1825 if (!CORBA::is_nil(anArgSO)) {
1826 SALOMEDS::SObject_var aSubSO;
1827 if (!CORBA::is_nil(theSObject))
1828 aSubSO = aStudyBuilder->NewObject(theSObject);
1830 // Restore published sub-shapes of the argument
1831 GEOM::ListOfGO_var aSubParts =
1832 RestoreGivenSubShapesOneLevel(anArgSO, aSubSO,
1833 theObject, anArgs, theFindMethod, theAddPrefix);
1835 // add to parts list
1836 addToListOfGO( aSubParts, aParts );
1838 if (aSubParts->length() > 0) {
1839 // try to build an argument from a set of its sub-shapes,
1840 // that published and will be reconstructed
1841 if (aSubParts->length() > 1) {
1842 aSubO = aShapesOp->MakeCompound(aSubParts);
1843 // add to parts list
1844 addToListOfGO( aSubO, aParts );
1847 aSubO = aSubParts[0];
1849 if (!CORBA::is_nil(aSubO) && !CORBA::is_nil(aSubSO)) {
1850 // Publish the sub-shape
1851 TCollection_AsciiString aSubName;
1853 aSubName = "from_parts_of_";
1855 aSubName += anArgName;
1856 aSubSO = PublishInStudy(aSubSO, aSubO, aSubName.ToCString());
1858 aSubO->SetColor(anArgO->GetColor());
1860 if (aSubO->GetShapeType() == GEOM::VERTEX) {
1861 aSubO->SetMarkerStd(anArgO->GetMarkerType(), anArgO->GetMarkerSize());
1862 if (anArgO->GetMarkerType() == GEOM::MT_USER)
1863 aSubO->SetMarkerTexture(anArgO->GetMarkerTexture());
1867 else if (!CORBA::is_nil(aSubSO)) {
1868 // remove created aSubSO, because no parts have been found
1869 aStudyBuilder->RemoveObject(aSubSO);
1872 } // try to build from published parts
1873 anArgSO->UnRegister();
1875 } // process arguments
1877 std::set<std::string> anObjEntryMap;
1878 GEOM::ListOfGO_var aResParts = new GEOM::ListOfGO;
1880 int nb = aParts->length();
1881 aResParts->length(nb);
1884 HANDLE_NAMESPACE(GEOM_BaseObject) aMainObj = _impl->GetObject(theObject->GetEntry());
1885 HANDLE_NAMESPACE(GEOM_Function) aFunction = aMainObj->GetLastFunction();
1886 GEOM::TPythonDump pd (aFunction, true);
1889 for ( ; i < nb; i++ )
1891 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_duplicate( aParts[ i ] );
1892 if (CORBA::is_nil(anObj))
1894 char* anEntry = anObj->GetEntry();
1895 if (anObjEntryMap.count(anEntry))
1896 continue; // already treated
1897 anObjEntryMap.insert(anEntry);
1898 aResParts[nbRes++] = anObj;
1899 // clear python dump of object
1900 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anEntry);
1901 HANDLE_NAMESPACE(GEOM_Function) anObjFun = aGeomObj->GetLastFunction();
1902 if ( !anObjFun.IsNull() )
1903 anObjFun->SetDescription( "" );
1909 pd <<"]" << " = geompy.RestoreGivenSubShapes(" << aMainObj << ", " << "[";
1910 i = 0; nb = theArgs.length(); j = 0;
1911 for ( ; i < nb; i++ )
1913 GEOM::GEOM_Object_var anObj = theArgs[ i ];
1914 if (CORBA::is_nil(anObj))
1916 HANDLE_NAMESPACE(GEOM_BaseObject) aGeomObj = _impl->GetObject(anObj->GetEntry());
1922 pd <<"]" << ", " <<"GEOM.";
1923 switch (theFindMethod) {
1924 case GEOM::FSM_GetInPlace:
1925 pd << "FSM_GetInPlace"; break;
1926 case GEOM::FSM_MultiTransformed:
1927 pd << "FSM_MultiTransformed"; break;
1928 case GEOM::FSM_Transformed:
1929 pd << "FSM_Transformed"; break;
1930 case GEOM::FSM_GetSame:
1931 pd << "FSM_GetSame"; break;
1932 case GEOM::FSM_GetShapesOnShape:
1933 pd << "FSM_GetShapesOnShape"; break;
1934 case GEOM::FSM_GetInPlaceByHistory:
1936 pd << "FSM_GetInPlaceByHistory"; break;
1938 pd << ", " << theInheritFirstArg << ", " << theAddPrefix << ")";
1940 aResParts->length(nbRes);
1941 return aResParts._retn();
1944 //============================================================================
1945 // function : RestoreGivenSubShapesOneLevel
1946 // purpose : Private method
1947 //============================================================================
1948 GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::SObject_ptr theOldSO,
1949 SALOMEDS::SObject_ptr theNewSO,
1950 GEOM::GEOM_Object_ptr theNewO,
1951 std::set<std::string> theArgs,
1952 GEOM::find_shape_method theFindMethod,
1953 CORBA::Boolean theAddPrefix)
1956 SALOMEDS::Study_var aStudy = getStudyServant();
1957 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
1958 GEOM::ListOfGO_var aNewParts = new GEOM::ListOfGO;
1959 if (CORBA::is_nil(aStudy) || CORBA::is_nil(theOldSO) ||
1960 CORBA::is_nil(theNewO) /*|| CORBA::is_nil(theNewSO)*/)
1961 return aParts._retn();
1963 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1965 // Get interface, containing method, which we will use to reconstruct sub-shapes
1966 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations();
1967 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations();
1968 GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations();
1970 PortableServer::Servant aServant = _poa->reference_to_servant(aTrsfOp.in());
1971 GEOM_ITransformOperations_i* aTrsfOpSv = dynamic_cast<GEOM_ITransformOperations_i*>(aServant);
1973 // Reconstruct published sub-shapes
1974 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(theOldSO);
1977 for (it->Init(); it->More(); it->Next()) {
1980 aParts->length(aLen);
1982 for (it->Init(); it->More(); it->Next()) {
1983 SALOMEDS::SObject_var anOldSubSO = it->Value();
1985 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1987 SALOMEDS::GenericAttribute_var anAttr;
1988 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1989 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1990 GEOM::GEOM_Object_var anOldSubO =
1991 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1993 bool okToContinue = false;
1995 if (!CORBA::is_nil(anOldSubO)) {
1996 CORBA::String_var anEntry = anOldSubO->GetEntry();
1997 okToContinue = theArgs.count(anEntry.in());
2001 // Find a sub-shape of theNewO in place of anOldSubO
2002 GEOM::GEOM_Object_var aNewSubO;
2003 switch (theFindMethod) {
2004 case GEOM::FSM_GetInPlace:
2007 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
2010 case GEOM::FSM_MultiTransformed:
2012 // Only for Multi-transformations
2013 GEOM::GEOM_Object_var anArgOTrsf = aTrsfOpSv->TransformLikeOtherCopy(anOldSubO, theNewO);
2014 if (!CORBA::is_nil(anArgOTrsf)) {
2015 CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry();
2016 HANDLE_NAMESPACE(GEOM_BaseObject) anArgOTrsfImpl = _impl->GetObject(anArgOTrsfEntry);
2017 HANDLE_NAMESPACE(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction();
2018 anArgOTrsfFun->SetDescription("");
2019 aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf);
2023 case GEOM::FSM_Transformed:
2025 // transformation, cannot use GetInPlace, operate with indices
2026 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
2027 if (anIDs->length() > 1) {
2029 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
2030 if (!CORBA::is_nil(aNewSubO))
2031 aGroupOp->UnionIDs(aNewSubO, anIDs);
2035 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
2039 case GEOM::FSM_GetSame:
2042 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
2045 case GEOM::FSM_GetShapesOnShape:
2047 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
2048 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
2049 (short)GEOM::SOLID, GEOM::ST_ONIN);
2052 case GEOM::FSM_GetInPlaceByHistory:
2054 // Use GetInPlaceByHistory
2055 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
2062 if (!CORBA::is_nil(aNewSubO)) {
2063 // add the part to the list
2064 aParts[i] = aNewSubO;
2066 // add to parts list
2067 addToListOfGO( aNewSubO, aNewParts );
2069 SALOMEDS::SObject_var aNewSubSO;
2070 if (!CORBA::is_nil(theNewSO)) {
2071 // Publish the sub-shape
2072 TCollection_AsciiString aSubName;
2076 aSubName += anArgName;
2077 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2078 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
2080 aNewSubO->SetColor(anOldSubO->GetColor());
2082 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2083 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2084 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2085 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2088 // Restore published sub-shapes of the argument
2089 GEOM::ListOfGO_var aSubParts;
2090 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
2091 // pass the main shape as Object, because only it has the history
2092 aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2093 theNewO, theArgs, theFindMethod, theAddPrefix);
2095 aSubParts = RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2096 aNewSubO, theArgs, theFindMethod, theAddPrefix);
2097 // add to parts list
2098 addToListOfGO( aSubParts, aNewParts );
2100 else { // GetInPlace failed, try to build from published parts
2101 SALOMEDS::SObject_var aNewSubSO;
2102 if (!CORBA::is_nil(theNewSO))
2103 aNewSubSO = aStudyBuilder->NewObject(theNewSO);
2105 // Restore published sub-shapes of the argument
2106 GEOM::ListOfGO_var aSubParts =
2107 RestoreGivenSubShapesOneLevel(anOldSubSO, aNewSubSO,
2108 theNewO, theArgs, theFindMethod, theAddPrefix);
2109 // add to parts list
2110 addToListOfGO( aSubParts, aNewParts );
2112 if (aSubParts->length() > 0) {
2113 // try to build an object from a set of its sub-shapes,
2114 // that published and will be reconstructed
2115 if (aSubParts->length() > 1) {
2116 aNewSubO = aShapesOp->MakeCompound(aSubParts);
2117 // add to parts list
2118 addToListOfGO( aNewSubO, aNewParts );
2121 aNewSubO = aSubParts[0];
2124 if (!CORBA::is_nil(aNewSubO)) {
2125 // add the part to the list
2126 aSubParts[i] = aNewSubO;
2129 // Publish the sub-shape
2130 if (!CORBA::is_nil(aNewSubSO)) {
2131 TCollection_AsciiString aSubName;
2133 aSubName = "from_parts_of_";
2135 aSubName += anArgName;
2136 aNewSubSO = PublishInStudy(aNewSubSO, aNewSubO, aSubName.ToCString());
2138 aNewSubO->SetColor(anOldSubO->GetColor());
2140 if (aNewSubO->GetShapeType() == GEOM::VERTEX) {
2141 aNewSubO->SetMarkerStd(anOldSubO->GetMarkerType(), anOldSubO->GetMarkerSize());
2142 if (anOldSubO->GetMarkerType() == GEOM::MT_USER)
2143 aNewSubO->SetMarkerTexture(anOldSubO->GetMarkerTexture());
2148 else if (!CORBA::is_nil(aNewSubSO)) {
2149 // remove created aSubSO, because no parts have been found
2150 aStudyBuilder->RemoveObject(aNewSubSO);
2152 } // try to build from published parts
2155 } // iterate on published sub-shapes
2158 // add to parts list
2159 addToListOfGO( aNewParts, aParts );
2160 return aParts._retn();
2163 //============================================================================
2164 // function : register()
2165 // purpose : register 'name' in 'name_service'
2166 //============================================================================
2167 void GEOM_Gen_i::register_name(char * name)
2169 GEOM::GEOM_Gen_var g = _this();
2170 name_service->Register(g, name);
2173 //============================================================================
2174 // function : getStudyServant()
2175 // purpose : Get Study
2176 //============================================================================
2177 SALOMEDS::Study_var GEOM_Gen_i::getStudyServant()
2179 static SALOMEDS::Study_var aStudy;
2180 if(CORBA::is_nil(aStudy)){
2181 CORBA::Object_ptr anObject = name_service->Resolve("/Study");
2182 aStudy = SALOMEDS::Study::_narrow(anObject);
2187 //============================================================================
2190 //============================================================================
2191 void GEOM_Gen_i::Undo()
2196 //============================================================================
2199 //============================================================================
2200 void GEOM_Gen_i::Redo()
2205 //============================================================================
2206 // function : GetIBasicOperations
2208 //============================================================================
2209 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations()
2210 throw ( SALOME::SALOME_Exception )
2212 Unexpect aCatch(SALOME_SalomeException);
2213 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
2215 GEOM::GEOM_Gen_ptr engine = _this();
2217 //transfer reference on engine
2218 GEOM_IBasicOperations_i* aServant =
2219 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations());
2221 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2222 // activate the CORBA servant
2223 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
2224 return operations._retn();
2227 //============================================================================
2228 // function : GetITransformOperations
2230 //============================================================================
2231 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations()
2232 throw ( SALOME::SALOME_Exception )
2234 Unexpect aCatch(SALOME_SalomeException);
2235 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
2237 GEOM::GEOM_Gen_ptr engine = _this();
2239 GEOM_ITransformOperations_i* aServant =
2240 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations());
2242 // activate the CORBA servant
2243 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
2244 return operations._retn();
2247 //============================================================================
2248 // function : GetI3DPrimOperations
2250 //============================================================================
2251 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations()
2252 throw ( SALOME::SALOME_Exception )
2254 Unexpect aCatch(SALOME_SalomeException);
2255 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
2257 GEOM::GEOM_Gen_ptr engine = _this();
2259 GEOM_I3DPrimOperations_i* aServant =
2260 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations());
2261 PortableServer::ObjectId_var id = _poa->activate_object(aServant);
2263 // activate the CORBA servant
2264 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
2265 return operations._retn();
2268 //============================================================================
2269 // function : GetIShapesOperations
2271 //============================================================================
2272 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations()
2273 throw ( SALOME::SALOME_Exception )
2275 Unexpect aCatch(SALOME_SalomeException);
2276 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
2278 GEOM::GEOM_Gen_ptr engine = _this();
2280 GEOM_IShapesOperations_i* aServant =
2281 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations());
2283 // activate the CORBA servant
2284 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
2285 return operations._retn();
2288 //============================================================================
2289 // function : GetIBlocksOperations
2291 //============================================================================
2292 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations()
2293 throw ( SALOME::SALOME_Exception )
2295 Unexpect aCatch(SALOME_SalomeException);
2296 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
2298 GEOM::GEOM_Gen_ptr engine = _this();
2300 GEOM_IBlocksOperations_i* aServant =
2301 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations());
2303 // activate the CORBA servant
2304 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
2305 return operations._retn();
2308 //============================================================================
2309 // function : GetIBooleanOperations
2311 //============================================================================
2312 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations()
2313 throw ( SALOME::SALOME_Exception )
2315 Unexpect aCatch(SALOME_SalomeException);
2316 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
2318 GEOM::GEOM_Gen_ptr engine = _this();
2320 GEOM_IBooleanOperations_i* aServant =
2321 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations());
2323 // activate the CORBA servant
2324 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
2325 return operations._retn();
2328 //============================================================================
2329 // function : GetICurvesOperations
2331 //============================================================================
2332 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations()
2333 throw ( SALOME::SALOME_Exception )
2335 Unexpect aCatch(SALOME_SalomeException);
2336 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
2338 GEOM::GEOM_Gen_ptr engine = _this();
2340 GEOM_ICurvesOperations_i* aServant =
2341 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations());
2343 // activate the CORBA servant
2344 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
2345 return operations._retn();
2348 //============================================================================
2349 // function : GetILocalOperations
2351 //============================================================================
2352 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations()
2353 throw ( SALOME::SALOME_Exception )
2355 Unexpect aCatch(SALOME_SalomeException);
2356 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
2358 GEOM::GEOM_Gen_ptr engine = _this();
2360 GEOM_ILocalOperations_i* aServant =
2361 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations());
2363 // activate the CORBA servant
2364 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
2365 return operations._retn();
2368 //============================================================================
2369 // function : GetIHealingOperations
2371 //============================================================================
2372 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations()
2373 throw ( SALOME::SALOME_Exception )
2375 Unexpect aCatch(SALOME_SalomeException);
2376 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
2378 GEOM::GEOM_Gen_ptr engine = _this();
2380 GEOM_IHealingOperations_i* aServant =
2381 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations());
2383 // activate the CORBA servant
2384 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
2385 return operations._retn();
2388 //============================================================================
2389 // function : GetIInsertOperations
2391 //============================================================================
2392 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations()
2393 throw ( SALOME::SALOME_Exception )
2395 Unexpect aCatch(SALOME_SalomeException);
2396 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
2398 GEOM::GEOM_Gen_ptr engine = _this();
2400 GEOM_IInsertOperations_i* aServant =
2401 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations());
2403 // activate the CORBA servant
2404 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
2405 return operations._retn();
2408 //============================================================================
2409 // function : GetIMeasureOperations
2411 //============================================================================
2412 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations()
2413 throw ( SALOME::SALOME_Exception )
2415 Unexpect aCatch(SALOME_SalomeException);
2416 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
2418 GEOM::GEOM_Gen_ptr engine = _this();
2420 GEOM_IMeasureOperations_i* aServant =
2421 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations());
2423 // activate the CORBA servant
2424 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
2425 return operations._retn();
2428 //============================================================================
2429 // function : GetIGroupOperations
2431 //============================================================================
2432 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations()
2433 throw ( SALOME::SALOME_Exception )
2435 Unexpect aCatch(SALOME_SalomeException);
2436 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
2438 GEOM::GEOM_Gen_ptr engine = _this();
2440 GEOM_IGroupOperations_i* aServant =
2441 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations());
2443 // activate the CORBA servant
2444 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
2445 return operations._retn();
2448 //============================================================================
2449 // function : GetIFieldOperations
2451 //============================================================================
2452 GEOM::GEOM_IFieldOperations_ptr GEOM_Gen_i::GetIFieldOperations()
2453 throw ( SALOME::SALOME_Exception )
2455 Unexpect aCatch(SALOME_SalomeException);
2456 MESSAGE( "GEOM_Gen_i::GetIFieldOperations" );
2458 GEOM::GEOM_Gen_ptr engine = _this();
2460 GEOM_IFieldOperations_i* aServant =
2461 new GEOM_IFieldOperations_i(_poa, engine, _impl->GetIFieldOperations());
2463 // activate the CORBA servant
2464 GEOM::GEOM_IFieldOperations_var operations = aServant->_this();
2465 return operations._retn();
2468 //============================================================================
2469 // function : GetPluginOperations
2471 //============================================================================
2472 GEOM::GEOM_IOperations_ptr GEOM_Gen_i::GetPluginOperations(const char* theLibName)
2473 throw ( SALOME::SALOME_Exception )
2475 Unexpect aCatch(SALOME_SalomeException);
2476 MESSAGE( "GEOM_Gen_i::GetPluginOperations" );
2478 GEOM::GEOM_Gen_ptr engine = _this();
2480 GEOM::GEOM_IOperations_var operations;
2482 std::string aLibName = theLibName;
2485 // load plugin library
2486 LoadPlugin(aLibName);
2487 // create a new operations object, store its ref. in engine
2488 if ( myOpCreatorMap.find(aLibName) != myOpCreatorMap.end() ) {
2489 GEOM_IOperations_i* aServant = 0;
2490 aServant = myOpCreatorMap[aLibName]->Create(_poa, engine, _impl);
2491 // activate the CORBA servant
2493 operations = aServant->_this();
2496 catch (SALOME_Exception& S_ex) {
2497 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
2500 return operations._retn();
2503 //============================================================================
2504 // function : LoadPlugin
2505 // purpose : load plugin library and retrieve an instance of operations creator
2506 //============================================================================
2507 void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
2509 std::string aPlatformLibName;
2511 aPlatformLibName = "lib";
2513 aPlatformLibName += theLibName;
2515 aPlatformLibName += ".dll" ;
2516 #elif defined(__APPLE__)
2517 aPlatformLibName += ".dylib";
2519 aPlatformLibName += ".so";
2522 // check, if corresponding operations are already created
2523 if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
2524 // load plugin library
2525 LibHandle libHandle = LoadLib( aPlatformLibName.c_str() );
2527 // report any error, if occured
2529 throw(SALOME_Exception(dlerror()));
2531 throw(SALOME_Exception(LOCALIZED( "Can't load server geometry plugin library" )));
2535 // get method, returning operations creator
2536 typedef GEOM_GenericOperationsCreator* (*GetOperationsCreator)();
2537 GetOperationsCreator procHandle =
2538 (GetOperationsCreator)GetProc( libHandle, "GetOperationsCreator" );
2540 UnLoadLib(libHandle);
2541 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library")));
2544 // get operations creator
2545 GEOM_GenericOperationsCreator* aCreator = procHandle();
2547 // map operations creator to a plugin name
2548 myOpCreatorMap[theLibName] = aCreator;
2551 throw(SALOME_Exception(LOCALIZED("bad geometry plugin library implementation")));
2556 //=============================================================================
2560 //=============================================================================
2561 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
2562 const GEOM::ListOfLong& theIndices)
2564 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
2565 return GEOM::GEOM_Object::_nil();
2566 CORBA::String_var entry = theMainShape->GetEntry();
2567 HANDLE_NAMESPACE(GEOM_Object) aMainShape = HANDLE_NAMESPACE(GEOM_Object)::DownCast
2568 ( _impl->GetObject( entry ));
2569 if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil();
2571 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
2572 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
2574 HANDLE_NAMESPACE(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true);
2575 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
2577 TCollection_AsciiString anEntry;
2578 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
2579 return GEOM::GEOM_Object::_narrow( GetObject(anEntry.ToCString()));
2582 //=============================================================================
2586 //=============================================================================
2587 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_BaseObject_ptr theObject)
2589 CORBA::String_var anEntry = theObject->GetEntry();
2590 HANDLE_NAMESPACE(GEOM_BaseObject) anObject = _impl->GetObject(anEntry, false);
2591 if (!anObject.IsNull())
2592 _impl->RemoveObject(anObject);
2595 //=================================================================================
2596 // function : GetStringFromIOR()
2597 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
2598 //=================================================================================
2599 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject)
2601 return _orb->object_to_string(theObject);
2604 //=================================================================================
2605 // function : GetIORFromString()
2606 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
2607 //=================================================================================
2608 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
2609 GEOM::GEOM_Object_var aGeomObject;
2610 if(strcmp(stringIOR,"") != 0){
2611 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
2612 if(!CORBA::is_nil(anObject))
2613 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
2615 return aGeomObject._retn();
2618 //=================================================================================
2619 // function : GetObject()
2621 //=================================================================================
2622 GEOM::GEOM_BaseObject_ptr GEOM_Gen_i::GetObject (const char* theEntry)
2624 GEOM::GEOM_BaseObject_var obj;
2625 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject((char*)theEntry);
2626 if (handle_object.IsNull()) return obj._retn();
2628 TCollection_AsciiString stringIOR = handle_object->GetIOR();
2629 if (stringIOR.Length() > 1) {
2630 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
2631 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_BaseObject::_narrow(corba_object);
2635 GEOM::GEOM_Gen_ptr engine = _this();
2636 //transfer the reference to GEOM_Object_i
2637 GEOM_BaseObject_i* servant = 0;
2638 switch( handle_object->GetType() ) {
2640 servant = new GEOM_Field_i (_poa, engine, HANDLE_NAMESPACE(GEOM_Field)::DownCast( handle_object ));
2643 case GEOM_FIELD_STEP: {
2644 HANDLE_NAMESPACE(GEOM_FieldStep) step = HANDLE_NAMESPACE(GEOM_FieldStep)::DownCast( handle_object );
2645 HANDLE_NAMESPACE(GEOM_Field) field = step->GetField();
2646 int type = ( !field.IsNull() ? field->GetDataType() : 0 );
2648 case GEOM::FDT_Bool:
2649 servant = new GEOM_BoolFieldStep_i (_poa, engine, step );
2652 servant = new GEOM_IntFieldStep_i (_poa, engine, step );
2654 case GEOM::FDT_Double:
2655 servant = new GEOM_DoubleFieldStep_i (_poa, engine, step );
2658 servant = new GEOM_StringFieldStep_i (_poa, engine, step );
2663 servant = new GEOM_Object_i (_poa, engine, HANDLE_NAMESPACE(GEOM_Object)::DownCast( handle_object ));
2665 PortableServer::ObjectId_var id = _poa->activate_object(servant);
2667 obj = servant->_this();
2668 CORBA::String_var objStr = _orb->object_to_string(obj);
2669 TCollection_AsciiString anAscii( (char *)objStr.in() );
2670 handle_object->SetIOR( anAscii );
2674 //=================================================================================
2675 // function : hasObjectInfo()
2676 // purpose : shows if module provides information for its objects
2677 //=================================================================================
2678 bool GEOM_Gen_i::hasObjectInfo()
2683 //=================================================================================
2684 // function : getObjectInfo()
2685 // purpose : returns an information for a given object by its entry
2686 //=================================================================================
2687 char* GEOM_Gen_i::getObjectInfo(const char* entry)
2689 GEOM::GEOM_Object_var aGeomObject;
2691 SALOMEDS::SObject_var aSObj = getStudyServant()->FindObjectID( entry );
2692 SALOMEDS::SObject_var aResultSObj;
2693 if (aSObj->ReferencedObject(aResultSObj))
2694 aSObj = aResultSObj;
2696 SALOMEDS::GenericAttribute_var anAttr;
2697 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
2698 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2699 CORBA::String_var aVal = anIOR->Value();
2700 anIOR->UnRegister();
2701 CORBA::Object_var anObject = getStudyServant()->ConvertIORToObject(aVal);
2702 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
2704 if (!aSObj->_is_nil() )
2705 aSObj->UnRegister();
2707 const char* aTypeInfo = "Object";
2708 if ( !aGeomObject->_is_nil() ) {
2709 GEOM::GEOM_IKindOfShape::shape_kind aKind;
2710 GEOM::ListOfLong_var anInts;
2711 GEOM::ListOfDouble_var aDbls;
2713 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations();
2714 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
2716 if ( anOp->IsDone() ) {
2718 case GEOM::GEOM_IKindOfShape::COMPOUND:
2719 aTypeInfo = "Compound";
2721 case GEOM::GEOM_IKindOfShape::COMPSOLID:
2722 aTypeInfo = "CompSolid";
2724 case GEOM::GEOM_IKindOfShape::SHELL:
2725 aTypeInfo = "Shell";
2727 case GEOM::GEOM_IKindOfShape::WIRE:
2728 if ( anInts[0] == 1 )
2729 aTypeInfo = "Closed Wire";
2730 else if ( anInts[0] == 2 )
2731 aTypeInfo = "Opened Wire";
2736 case GEOM::GEOM_IKindOfShape::SPHERE:
2737 aTypeInfo = "Sphere";
2739 case GEOM::GEOM_IKindOfShape::CYLINDER:
2740 aTypeInfo = "Cylinder";
2742 case GEOM::GEOM_IKindOfShape::BOX:
2743 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
2746 case GEOM::GEOM_IKindOfShape::TORUS:
2747 aTypeInfo = "Torus";
2749 case GEOM::GEOM_IKindOfShape::CONE:
2752 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
2753 aTypeInfo = "Polyhedron";
2755 case GEOM::GEOM_IKindOfShape::SOLID:
2756 aTypeInfo = "Solid";
2759 case GEOM::GEOM_IKindOfShape::SPHERE2D:
2760 aTypeInfo = "Spherical Face";
2762 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
2763 aTypeInfo = "Cylindrical Face";
2765 case GEOM::GEOM_IKindOfShape::TORUS2D:
2766 aTypeInfo = "Toroidal Face";
2768 case GEOM::GEOM_IKindOfShape::CONE2D:
2769 aTypeInfo = "Conical Face";
2771 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
2774 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
2775 aTypeInfo = "Elliptical Face";
2777 case GEOM::GEOM_IKindOfShape::POLYGON:
2778 aTypeInfo = "Polygon";
2780 case GEOM::GEOM_IKindOfShape::PLANE:
2781 aTypeInfo = "Plane";
2783 case GEOM::GEOM_IKindOfShape::PLANAR:
2784 aTypeInfo = "Planar Face";
2786 case GEOM::GEOM_IKindOfShape::FACE:
2790 case GEOM::GEOM_IKindOfShape::CIRCLE:
2791 aTypeInfo = "Circle";
2793 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
2794 aTypeInfo = "Arc Circle";
2796 case GEOM::GEOM_IKindOfShape::ELLIPSE:
2797 aTypeInfo = "Ellipse";
2799 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
2800 aTypeInfo = "Arc Ellipse";
2802 case GEOM::GEOM_IKindOfShape::LINE:
2805 case GEOM::GEOM_IKindOfShape::SEGMENT:
2806 aTypeInfo = "Segment";
2808 case GEOM::GEOM_IKindOfShape::EDGE:
2811 case GEOM::GEOM_IKindOfShape::VERTEX:
2812 aTypeInfo = "Vertex";
2820 CORBA::String_var compType = ComponentDataType();
2821 char* anInfo = new char[strlen("Module ") + strlen(compType.in()) + strlen(", ") + strlen(aTypeInfo) + 3];
2822 sprintf(anInfo, "Module %s, %s", compType.in(), aTypeInfo);
2824 char* ret = CORBA::string_dup(anInfo);
2829 // Version information
2830 char* GEOM_Gen_i::getVersion()
2832 #if GEOM_DEVELOPMENT
2833 return CORBA::string_dup(GEOM_VERSION_STR"dev");
2835 return CORBA::string_dup(GEOM_VERSION_STR);
2839 //=================================================================================
2840 // function : CreateFolder()
2841 // purpose : Creates and returns a new folder object
2842 //=================================================================================
2843 SALOMEDS::SObject_ptr GEOM_Gen_i::CreateFolder(const char* theName,
2844 SALOMEDS::SObject_ptr theFather)
2846 SALOMEDS::SObject_var aFolderSO;
2848 if ( CORBA::is_nil(theFather) ) return aFolderSO._retn();
2850 SALOMEDS::GenericAttribute_var anAttr;
2851 if ( strcmp(theFather->GetFatherComponent()->GetID(), theFather->GetID()) != 0 ) {
2852 // not a GEOM component object was selected
2853 if ( !theFather->FindAttribute(anAttr, "AttributeLocalID") ) return aFolderSO._retn();
2854 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2855 if( aLocalID->Value() != 999 ) {
2856 // not a Folder object was selected
2857 GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow(theFather);
2858 if ( CORBA::is_nil(aGeomObject) ) return aFolderSO._retn();
2859 // another GEOM object was selected, so get GEOM component as father object
2860 theFather = theFather->GetFatherComponent();
2862 aLocalID->UnRegister();
2865 SALOMEDS::Study_var aStudy = getStudyServant();
2866 SALOMEDS::StudyBuilder_var aStudyBuilder( aStudy->NewBuilder() );
2867 aFolderSO = aStudyBuilder->NewObject( theFather );
2869 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeLocalID");
2870 SALOMEDS::AttributeLocalID_var aLocalID = SALOMEDS::AttributeLocalID::_narrow(anAttr);
2871 aLocalID->SetValue( 999 ); // mark of the "Folder" object
2872 aLocalID->UnRegister();
2874 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributeName");
2875 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
2876 aName->SetValue( theName );
2877 aName->UnRegister();
2879 anAttr = aStudyBuilder->FindOrCreateAttribute(aFolderSO, "AttributePixMap");
2880 SALOMEDS::AttributePixMap_var aPixMap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2881 aPixMap->SetPixMap("ICON_FOLDER");
2882 aPixMap->UnRegister();
2884 // add object to the use case tree
2885 // (to support tree representation customization and drag-n-drop)
2886 SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder();
2887 useCaseBuilder->AppendTo( theFather, aFolderSO );
2889 return aFolderSO._retn();
2892 //=================================================================================
2893 // function : MoveToFolder()
2894 // purpose : Moves GEOM object to the specified folder
2895 //=================================================================================
2896 void GEOM_Gen_i::MoveToFolder(GEOM::GEOM_Object_ptr theObject,
2897 SALOMEDS::SObject_ptr theFolder) {
2898 GEOM::object_list_var objects = new GEOM::object_list();
2899 objects->length( 1 );
2900 SALOMEDS::SObject_var aSO = getStudyServant()->FindObjectID( theObject->GetStudyEntry() );
2902 Move( objects, theFolder, -1 );
2905 //=================================================================================
2906 // function : MoveListToFolder()
2907 // purpose : Moves list of GEOM objects to the specified folder
2908 //=================================================================================
2909 void GEOM_Gen_i::MoveListToFolder (const GEOM::ListOfGO& theListOfGO,
2910 SALOMEDS::SObject_ptr theFolder) {
2911 int aLen = theListOfGO.length();
2912 GEOM::object_list_var objects = new GEOM::object_list();
2913 objects->length( aLen );
2914 GEOM::GEOM_Object_var aGO;
2915 SALOMEDS::SObject_var aSO;
2916 for (int i = 0; i < aLen; i++) {
2917 aGO = GEOM::GEOM_Object::_duplicate( theListOfGO[i] );
2918 aSO = getStudyServant()->FindObjectID( aGO->GetStudyEntry() );
2921 if ( objects->length() > 0 )
2922 Move( objects, theFolder, -1 );
2925 //=================================================================================
2926 // function : Move()
2927 // purpose : Moves objects to the specified position.
2928 // Is used in the drag-n-drop functionality.
2929 //=================================================================================
2930 void GEOM_Gen_i::Move( const GEOM::object_list& what,
2931 SALOMEDS::SObject_ptr where,
2934 if ( CORBA::is_nil( where ) ) return;
2936 SALOMEDS::Study_var study = getStudyServant();
2937 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
2938 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
2939 SALOMEDS::SComponent_var father = where->GetFatherComponent();
2940 std::string dataType = father->ComponentDataType();
2941 if ( dataType != "GEOM" ) return; // not a GEOM component
2943 SALOMEDS::SObject_var objAfter;
2944 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
2945 // insert at given row -> find insertion position
2946 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
2948 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
2949 if ( i == row && useCaseIt->More() ) {
2950 objAfter = useCaseIt->Value();
2954 for ( int i = 0; i < what.length(); i++ ) {
2955 SALOMEDS::SObject_var sobj = what[i];
2956 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
2957 // insert the object to the use case tree
2958 if ( !CORBA::is_nil( objAfter ) )
2959 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
2961 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
2965 //=======================================================================
2966 // function : GetDependencyTree
2967 // purpose : Collects dependencies of the given objects from other ones
2968 //=======================================================================
2969 SALOMEDS::TMPFile* GEOM_Gen_i::GetDependencyTree( const GEOM::string_array& theObjectEntries )
2971 // fill in the tree structure
2972 GEOMUtils::TreeModel tree;
2975 for ( int i = 0; i < theObjectEntries.length(); i++ ) {
2976 // process objects one-by-one
2977 entry = theObjectEntries[i].in();
2978 GEOM::GEOM_BaseObject_var anObj = GetObject(entry.c_str() );
2979 if ( anObj->_is_nil() )
2981 std::map< std::string, std::set<std::string> > passedEntries;
2982 GEOMUtils::LevelsList upLevelList;
2983 // get objects from which current one depends on recursively
2984 getUpwardDependency( anObj, upLevelList, passedEntries );
2985 GEOMUtils::LevelsList downLevelList;
2986 // get objects that depends on current one recursively
2987 getDownwardDependency( anObj, downLevelList, passedEntries );
2988 tree.insert( std::pair<std::string, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList> >(entry, std::pair<GEOMUtils::LevelsList,GEOMUtils::LevelsList>( upLevelList, downLevelList ) ) );
2991 // translation the tree into string
2992 std::string treeStr;
2993 GEOMUtils::ConvertTreeToString( tree, treeStr );
2995 // put string into stream
2996 char* aBuffer = (char*)CORBA::string_dup(treeStr.c_str());
2997 int aBufferSize = strlen((char*)aBuffer);
2999 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
3001 SALOMEDS::TMPFile_var aStream = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
3003 return aStream._retn();
3006 //=======================================================================
3007 // function : getUpwardDependency
3008 // purpose : Collects the entries of objects on that the given one depends
3009 //=======================================================================
3010 void GEOM_Gen_i::getUpwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3011 GEOMUtils::LevelsList &upLevelList,
3012 std::map< std::string, std::set<std::string> > &passedEntries,
3014 std::string aGboEntry = gbo->GetEntry();
3015 GEOMUtils::NodeLinks anEntries;
3016 GEOMUtils::LevelInfo aLevelMap;
3018 if ( level-1 >= upLevelList.size() ) {
3020 upLevelList.push_back( aLevelMap );
3022 // get the existent map
3023 aLevelMap = upLevelList.at(level-1);
3024 if ( aLevelMap.count( aGboEntry ) > 0 ) {
3025 anEntries = aLevelMap[ aGboEntry ];
3029 // get objects on that the current one depends
3030 GEOM::ListOfGBO_var depList = gbo->GetDependency();
3031 std::string aDepEntry;
3032 for( int j = 0; j < depList->length(); j++ ) {
3033 if ( depList[j]->_is_nil() )
3035 aDepEntry = depList[j]->GetEntry();
3036 if ( passedEntries.count( aGboEntry ) > 0 &&
3037 passedEntries[aGboEntry].count( aDepEntry ) > 0 ) {
3038 //avoid checking the passed objects
3041 passedEntries[aGboEntry].insert( aDepEntry );
3043 anEntries.push_back( aDepEntry );
3045 // get dependencies recursively
3046 getUpwardDependency(depList[j], upLevelList, passedEntries, level+1);
3049 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGboEntry, anEntries) );
3050 upLevelList[level-1] = aLevelMap;
3054 //=======================================================================
3055 // function : getDownwardDependency
3056 // purpose : Collects the entries of objects that depends on the given one
3057 //=======================================================================
3058 void GEOM_Gen_i::getDownwardDependency( GEOM::GEOM_BaseObject_ptr gbo,
3059 GEOMUtils::LevelsList &downLevelList,
3060 std::map< std::string, std::set<std::string> > &passedEntries,
3062 std::string aGboEntry = gbo->GetEntry();
3063 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument();
3064 Handle(TDataStd_TreeNode) aNode, aRoot;
3065 HANDLE_NAMESPACE(GEOM_Function) aFunction;
3066 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3067 // go through the whole OCAF tree
3068 TDataStd_ChildNodeIterator Itr( aRoot );
3069 for (; Itr.More(); Itr.Next()) {
3070 aNode = Itr.Value();
3071 aFunction = GEOM_Function::GetFunction(aNode->Label());
3072 if (aFunction.IsNull()) {
3075 TDF_Label aLabel = aFunction->GetOwnerEntry();
3076 if(aLabel.IsNull()) continue;
3077 TCollection_AsciiString anEntry;
3078 TDF_Tool::Entry(aLabel, anEntry);
3079 GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.ToCString() );
3080 if( CORBA::is_nil( geomObj ) )
3082 // get dependencies for current object in the tree
3083 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3084 if( depList->length() == 0 )
3086 std::string aGoEntry = geomObj->GetEntry();
3087 // go through dependencies of current object to check whether it depends on the given object
3088 for( int i = 0; i < depList->length(); i++ ) {
3089 if ( depList[i]->_is_nil() )
3091 if ( depList[i]->_is_equivalent( gbo ) ) {
3092 // yes, the current object depends on the given object
3093 if ( passedEntries.count( aGoEntry ) > 0 &&
3094 passedEntries[aGoEntry].count( aGboEntry ) > 0 ) {
3095 //avoid checking the passed objects
3098 passedEntries[aGoEntry].insert( aGboEntry );
3099 GEOMUtils::NodeLinks anEntries;
3100 GEOMUtils::LevelInfo aLevelMap;
3101 anEntries.push_back( aGboEntry );
3102 if ( level >= downLevelList.size() ) {
3103 downLevelList.push_back( aLevelMap );
3105 aLevelMap = downLevelList.at(level);
3106 if ( aLevelMap.count( aGoEntry ) > 0 ) {
3107 anEntries = aLevelMap[ aGoEntry ];
3110 aLevelMap.insert( std::pair<std::string, GEOMUtils::NodeLinks>(aGoEntry, anEntries) );
3111 downLevelList[level] = aLevelMap;
3112 // get dependencies of the current object recursively
3113 getDownwardDependency(geomObj, downLevelList, passedEntries, level+1);
3121 //==============================================================================
3122 // function : GetEntriesToReduceStudy
3123 // purpose : Fills 3 lists that is used to clean study of redundant objects
3124 //==============================================================================
3125 void GEOM_Gen_i::GetEntriesToReduceStudy(GEOM::string_array& theSelectedEntries,
3126 GEOM::string_array& theParentEntries,
3127 GEOM::string_array& theSubEntries,
3128 GEOM::string_array& theOtherEntries)
3130 std::set<std::string> aSelected, aParents, aChildren, anOthers;
3131 for ( int i = 0; i < theSelectedEntries.length(); i++ ) {
3132 aSelected.insert( CORBA::string_dup( theSelectedEntries[i] ) );
3135 Handle(TDocStd_Document) aDoc = GEOM_Engine::GetEngine()->GetDocument();
3136 Handle(TDataStd_TreeNode) aNode, aRoot;
3137 HANDLE_NAMESPACE(GEOM_Function) aFunction;
3138 if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
3139 // go through the whole OCAF tree
3141 std::string anEntry;
3142 TCollection_AsciiString anAsciiEntry;
3143 TDataStd_ChildNodeIterator Itr( aRoot );
3144 for (; Itr.More(); Itr.Next()) {
3145 aNode = Itr.Value();
3146 aFunction = GEOM_Function::GetFunction(aNode->Label());
3147 if (aFunction.IsNull()) {
3150 aLabel = aFunction->GetOwnerEntry();
3153 TDF_Tool::Entry(aLabel, anAsciiEntry);
3154 anEntry = anAsciiEntry.ToCString();
3155 GEOM::GEOM_BaseObject_var geomObj = GetObject(anEntry.c_str() );
3156 if( CORBA::is_nil( geomObj ) )
3159 if ( aSelected.count( anEntry ) > 0 &&
3160 aParents.count( anEntry ) == 0 ) {
3161 includeParentDependencies( geomObj, aSelected, aParents, aChildren, anOthers );
3162 } else if ( aParents.count( anEntry ) == 0 &&
3163 aChildren.count( anEntry ) == 0 ) {
3164 anOthers.insert( geomObj->GetEntry() );
3168 std::set<std::string>::iterator it;
3169 std::set<std::string>::iterator foundIt;
3170 TCollection_AsciiString stringIOR;
3171 GEOM::GEOM_Object_var geomObj;
3173 // filling list of sub-objects
3174 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3175 includeSubObjects( *it, aSelected, aParents, aChildren, anOthers );
3178 // if some selected object is not a main shape,
3179 // we move it's main shapes into 'selected' list,
3180 // because they could not be modified anyhow.
3181 std::set<std::string> aToBeInSelected;
3182 for ( it = aSelected.begin(); it != aSelected.end(); ++it ) {
3183 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject((*it).c_str(), false);
3184 if ( handle_object.IsNull() )
3187 stringIOR = handle_object->GetIOR();
3188 if ( !stringIOR.Length() > 1 )
3191 geomObj = GetIORFromString( stringIOR.ToCString() );
3192 while ( !geomObj->IsMainShape() ) {
3193 geomObj = geomObj->GetMainShape();
3194 anEntry = geomObj->GetEntry();
3196 foundIt = aParents.find( anEntry );
3197 if ( foundIt != aParents.end() )
3198 aParents.erase( foundIt );
3200 foundIt = aChildren.find( anEntry );
3201 if ( foundIt != aChildren.end() )
3202 aChildren.erase( foundIt );
3204 foundIt = anOthers.find( anEntry );
3205 if ( foundIt != anOthers.end() )
3206 anOthers.erase( foundIt );
3208 aToBeInSelected.insert( anEntry );
3211 aSelected.insert( aToBeInSelected.begin(), aToBeInSelected.end() );
3213 // fill the CORBA arrays with values from sets
3215 theSelectedEntries.length( aSelected.size() );
3216 for ( i = 0, it = aSelected.begin(); it != aSelected.end(); ++it, i++ )
3217 theSelectedEntries[i] = CORBA::string_dup( (*it).c_str() );
3218 theParentEntries.length( aParents.size() );
3219 for ( i = 0, it = aParents.begin(); it != aParents.end(); ++it, i++ )
3220 theParentEntries[i] = CORBA::string_dup( (*it).c_str() );
3221 theSubEntries.length( aChildren.size() );
3222 for ( i = 0, it = aChildren.begin(); it != aChildren.end(); ++it, i++ )
3223 theSubEntries[i] = CORBA::string_dup( (*it).c_str() );
3224 theOtherEntries.length( anOthers.size() );
3225 for ( i = 0, it = anOthers.begin(); it != anOthers.end(); ++it, i++ )
3226 theOtherEntries[i] = CORBA::string_dup( (*it).c_str() );
3230 //==============================================================================
3231 // function : includeParentDependencies
3233 //==============================================================================
3234 void GEOM_Gen_i::includeParentDependencies(GEOM::GEOM_BaseObject_ptr geomObj,
3235 std::set<std::string>& aSelected,
3236 std::set<std::string>& aParents,
3237 std::set<std::string>& aChildren,
3238 std::set<std::string>& anOthers)
3240 std::string anEntry = geomObj->GetEntry();
3241 if ( aSelected.count( anEntry ) == 0 ) {
3242 aParents.insert( anEntry );
3243 std::set<std::string>::iterator it;
3244 it = aChildren.find( anEntry );
3245 if ( it != aChildren.end() )
3246 aChildren.erase( it );
3247 it = anOthers.find( anEntry );
3248 if ( it != anOthers.end() )
3249 anOthers.erase( it );
3251 // get dependencies for current object in the tree
3252 GEOM::ListOfGBO_var depList = geomObj->GetDependency();
3253 if( depList->length() == 0 )
3255 // go through dependencies of current object to check whether it depends on the given object
3256 std::string aDepEntry;
3257 for( int i = 0; i < depList->length(); i++ ) {
3258 aDepEntry = depList[i]->GetEntry();
3259 if ( depList[i]->_is_nil() ||
3260 aDepEntry == anEntry || // skip self-depending
3261 aSelected.count( aDepEntry ) > 0 || // skip selected objects
3262 aParents.count( aDepEntry ) > 0 // skip already processed objects
3265 includeParentDependencies( depList[i], aSelected, aParents, aChildren, anOthers );
3269 //==============================================================================
3270 // function : includeSubObjects
3272 //==============================================================================
3273 void GEOM_Gen_i::includeSubObjects(const std::string& aSelectedEntry,
3274 std::set<std::string>& aSelected,
3275 std::set<std::string>& aParents,
3276 std::set<std::string>& aChildren,
3277 std::set<std::string>& anOthers)
3279 std::set<std::string>::iterator foundIt;
3280 HANDLE_NAMESPACE(GEOM_BaseObject) handle_object = _impl->GetObject(aSelectedEntry.c_str(), false);
3281 if ( handle_object.IsNull() )
3284 HANDLE_NAMESPACE(GEOM_Function) aShapeFun = handle_object->GetFunction(1);
3285 if ( aShapeFun.IsNull() || !aShapeFun->HasSubShapeReferences() )
3288 const TDataStd_ListOfExtendedString& aListEntries = aShapeFun->GetSubShapeReferences();
3289 if ( aListEntries.IsEmpty() )
3292 TDataStd_ListIteratorOfListOfExtendedString anIt (aListEntries);
3293 for ( ; anIt.More(); anIt.Next() ) {
3294 TCollection_ExtendedString aSubEntry = anIt.Value();
3295 Standard_Integer aStrLen = aSubEntry.LengthOfCString();
3296 char* aSubEntryStr = new char[aStrLen+1];
3297 aSubEntry.ToUTF8CString( aSubEntryStr );
3298 foundIt = aParents.find( aSubEntryStr );
3299 if ( foundIt == aParents.end() ) { // add to sub-objects if it is not in parents list
3300 foundIt = aSelected.find( aSubEntryStr );
3301 if ( foundIt == aSelected.end() ) { // add to sub-objects if it is not in selected list
3302 aChildren.insert( aSubEntryStr );
3303 foundIt = anOthers.find( aSubEntryStr );
3304 if ( foundIt != anOthers.end() )
3305 anOthers.erase( foundIt );
3308 includeSubObjects( aSubEntryStr, aSelected, aParents, aChildren, anOthers );
3311 //=====================================================================================
3313 //=====================================================================================
3318 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB*, PortableServer::POA*, PortableServer::ObjectId*, const char*, const char*);
3322 PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
3323 PortableServer::POA_ptr poa,
3324 PortableServer::ObjectId* contId,
3325 const char* instanceName,
3326 const char* interfaceName)
3328 GEOM_Gen_i* myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
3329 return myGEOM_Gen_i->getId();