1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning( disable:4786 )
26 #include <Standard_Stream.hxx>
28 #include "GEOM_Gen_i.hh"
29 #include "GEOM_Object_i.hh"
34 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "GEOM_Object_i.hh"
40 #include "GEOM_Object.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOM_ISubShape.hxx"
43 #include "GEOMImpl_Types.hxx"
44 #include "GEOMImpl_CopyDriver.hxx"
47 #include <BRep_Builder.hxx>
48 #include <BRepTools.hxx>
49 #include <TDF_Label.hxx>
50 #include <TDF_Tool.hxx>
51 #include <TDF_ChildIDIterator.hxx>
52 #include <TNaming_NamedShape.hxx>
53 #include <TDataStd_Name.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <TColStd_HArray1OfInteger.hxx>
56 #include <TopAbs_ShapeEnum.hxx>
57 //#include <TopTools_IndexedMapOfShape.hxx>
61 #include "SALOMEDS_Tool.hxx"
63 //============================================================================
64 // function : GEOM_Gen_i()
65 // purpose : constructor to be called for servant creation.
66 //============================================================================
67 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
68 PortableServer::POA_ptr poa,
69 PortableServer::ObjectId * contId,
70 const char *instanceName,
71 const char *interfaceName) :
72 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
75 _id = _poa->activate_object(_thisObj);
76 name_service = new SALOME_NamingService(_orb);
78 _impl = new ::GEOMImpl_Gen;
80 //PAL10867: disable signals catching with "noexcepthandler" option
81 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
82 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
84 //work around PAL12004, PAL12628
85 //OSD::SetSignal( true );
89 char* envDisableFPE = getenv("DISABLE_FPE");
90 if (envDisableFPE && atoi(envDisableFPE))
95 OSD::SetSignal( raiseFPE );
99 //============================================================================
100 // function : ~GEOM_Gen_i()
101 // purpose : destructor
102 //============================================================================
103 GEOM_Gen_i::~GEOM_Gen_i() {
109 //============================================================================
110 // function : IORToLocalPersistentID()
112 //============================================================================
113 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
114 const char* IORString,
115 CORBA::Boolean isMultiFile,
116 CORBA::Boolean isASCII)
118 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
119 if (!CORBA::is_nil(anObject)) {
120 return CORBA::string_dup(anObject->GetEntry());
126 //============================================================================
127 // function : LocalPersistentIDToIOR()
128 // purpose : Create/Load CORBA object from a persistent ref (an entry)
129 // : Used when a study is loaded
130 // : The IOR (IORName) of object created is returned
131 //============================================================================
132 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
133 const char* aLocalPersistentID,
134 CORBA::Boolean isMultiFile,
135 CORBA::Boolean isASCII)
137 SALOMEDS::Study_var aStudy = theSObject->GetStudy();
139 Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
140 TCollection_AsciiString anEntry;
141 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
142 GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
144 CORBA::String_var aPersRefString = _orb->object_to_string(obj);
145 return CORBA::string_dup(aPersRefString);
148 //============================================================================
149 // function : CanPublishInStudy
151 //============================================================================
152 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
154 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
155 return !(anObject->_is_nil());
159 //============================================================================
160 // function : PublishInStudy
162 //============================================================================
163 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
164 SALOMEDS::SObject_ptr theSObject,
165 CORBA::Object_ptr theObject,
166 const char* theName) throw (SALOME::SALOME_Exception)
168 Unexpect aCatch(SALOME_SalomeException);
169 SALOMEDS::SObject_var aResultSO;
170 if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
171 GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
172 if(aShape->_is_nil()) return aResultSO;
174 SALOMEDS::GenericAttribute_var anAttr;
175 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
177 SALOMEDS::SComponent_var aFather = theStudy->FindComponent("GEOM");
178 if (aFather->_is_nil()) {
179 aFather = aStudyBuilder->NewComponent("GEOM");
180 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
181 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
182 aName->SetValue("Geometry");
183 anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
184 SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
185 aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
187 if (aFather->_is_nil()) return aResultSO;
189 if (CORBA::is_nil(theSObject)) {
190 aResultSO = aStudyBuilder->NewObject(aFather);
192 if (!theSObject->ReferencedObject(aResultSO))
193 aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for the method AddInStudy with theFather argumenet != NULL
194 //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
196 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
197 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
198 //char *aGeomObjIOR = _orb->object_to_string(theObject);
199 CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
200 //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
201 anIOR->SetValue(aGeomObjIOR);
203 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
204 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
205 TCollection_AsciiString aShapeName("Shape_");
207 if ( aShape->GetType() == GEOM_GROUP ) {
208 GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
209 switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
211 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
212 aShapeName = "Group_Of_Vertices_";
215 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
216 aShapeName = "Group_Of_Edges_";
219 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
220 aShapeName = "Group_Of_Faces_";
223 aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
224 aShapeName = "Group_Of_Solids_";
227 } else if ( aShape->GetType() == GEOM_MARKER ) {
228 aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
229 aShapeName = "LocalCS_";
230 } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
231 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
232 aShapeName = "Compound_";
233 } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
234 aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
235 aShapeName = "Compsolid_";
236 } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
237 aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
238 aShapeName = "Solid_";
239 } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
240 aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
241 aShapeName = "Shell_";
242 } else if ( aShape->GetShapeType() == GEOM::FACE ) {
243 aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
244 aShapeName = "Face_";
245 } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
246 aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
247 aShapeName = "Wire_";
248 } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
249 aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
250 aShapeName = "Edge_";
251 } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
252 aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
253 aShapeName = "Vertex_";
255 //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
256 //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
258 // try to find existed name for current shape
259 bool HasName = false;
260 // recieve current TopoDS shape
261 CORBA::String_var entry = aShape->GetEntry();
262 Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
263 TopoDS_Shape TopoSh = aGShape->GetValue();
264 // find label of main shape
265 GEOM::GEOM_Object_var aMainShVar = aShape;
266 GEOM::GEOM_Object_ptr aMainSh = aMainShVar._retn();
267 while( !aMainSh->IsMainShape() ) {
268 aMainSh = aMainSh->GetMainShape();
270 entry = aMainSh->GetEntry();
271 Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
272 TDF_Label aMainLbl = anObj->GetEntry();
273 // check all named shapes using iterator
274 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
275 for(; anIt.More(); anIt.Next()) {
276 Handle(TNaming_NamedShape) anAttr =
277 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
278 if(anAttr.IsNull()) continue;
279 TopoDS_Shape S = anAttr->Get();
280 if( !S.IsEqual(TopoSh) ) continue;
281 TDF_Label L = anAttr->Label();
282 Handle(TDataStd_Name) aName;
283 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
284 aShapeName = aName->Get();
290 // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
291 // it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
292 // of objects in the study, but compute a number of objects with the same prefix
293 // and build a new name as Prefix_N+1
294 if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
295 int i = 0; // (WITH EMPTY NEW NAME)
296 SALOMEDS::SObject_var obj;
297 TCollection_AsciiString aNewShapeName;
299 aNewShapeName = aShapeName + TCollection_AsciiString(++i);
300 obj = theStudy->FindObject( aNewShapeName.ToCString() );
302 while ( !obj->_is_nil() );
303 aShapeName = aNewShapeName;
305 else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
306 aShapeName = TCollection_AsciiString((char*)theName);
309 //Set the study entry as a name of the published GEOM_Object
310 aShape->SetStudyEntry(aResultSO->GetID());
312 //Set a name of the added shape
313 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
314 SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
315 aNameAttrib->SetValue(aShapeName.ToCString());
317 //Set NoteBook variables used in the object creation
318 TCollection_AsciiString aVars;
319 SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
320 for(int i = 0, n = aSections->length(); i < n; i++) {
321 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
322 for(int j = 0, m = aListOfVars.length(); j < m; j++) {
323 if(theStudy->IsVariable(aListOfVars[j].in()))
324 aVars += TCollection_AsciiString(aListOfVars[j].in());
331 anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
332 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
333 aStringAttrib->SetValue(aVars.ToCString());
335 //Set a name of the GEOM object
336 aShape->SetName(theName);
338 return aResultSO._retn();
342 //============================================================================
343 // function : CreateAndPublishGroup
344 // purpose : auxilary for PublishNamedShapesInStudy
345 //============================================================================
346 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
347 GEOM::GEOM_Object_var theMainShape,
348 const TopTools_IndexedMapOfShape& anIndices,
349 const TopTools_SequenceOfShape& SeqS,
350 const TColStd_SequenceOfAsciiString& SeqN,
351 const Standard_CString& GrName,
352 GEOM::ListOfGO_var aResList)
354 CORBA::String_var entry = theMainShape->GetEntry();
355 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
356 Handle(TColStd_HArray1OfInteger) anArray;
357 if(SeqS.Length()>0) {
359 GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
360 GEOM::GEOM_Object_ptr GrObj =
361 GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
362 AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
364 Handle(GEOM_Object) anObj;
365 for(int i=1; i<=SeqS.Length(); i++) {
366 TopoDS_Shape aValue = SeqS.Value(i);
367 anArray = new TColStd_HArray1OfInteger(1,1);
368 Standard_Integer anIndex = anIndices.FindIndex(aValue);
369 anArray->SetValue(1, anIndex);
370 anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
371 if (anObj.IsNull()) continue;
372 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
373 if (aFunction.IsNull()) continue;
374 GEOM_ISubShape aSSI(aFunction);
375 aSSI.SetMainShape(aMainShape->GetLastFunction());
376 aSSI.SetIndices(anArray);
377 aFunction->SetValue(aValue);
378 GOp->UnionIDs(GrObj, anIndex);
379 SALOMEDS::SObject_var aResultSO;
380 TCollection_AsciiString anEntry;
381 TDF_Tool::Entry(anObj->GetEntry(),anEntry);
382 GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
383 AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
389 //============================================================================
390 // function : PublishNamedShapesInStudy
392 //============================================================================
393 GEOM::ListOfGO* GEOM_Gen_i::
394 PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
395 //SALOMEDS::SObject_ptr theSObject,
396 CORBA::Object_ptr theObject)
398 //Unexpect aCatch(SALOME_SalomeException);
399 GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
401 //CORBA::Object_var theObject = theSObject->GetObject();
402 GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
403 if(theMainShape->_is_nil()) return aResList._retn();
405 CORBA::String_var entry = theMainShape->GetEntry();
406 Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
407 if (aMainShape.IsNull()) return aResList._retn();
408 TopoDS_Shape MainSh = aMainShape->GetValue();
410 TDF_Label aMainLbl = aMainShape->GetEntry();
411 TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
412 TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
413 TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
414 for(; anIt.More(); anIt.Next()) {
415 Handle(TNaming_NamedShape) anAttr =
416 Handle(TNaming_NamedShape)::DownCast(anIt.Value());
417 if(anAttr.IsNull()) continue;
418 TopoDS_Shape S = anAttr->Get();
419 TDF_Label L = anAttr->Label();
420 //if(S.IsEqual(MainSh)) continue;
421 Handle(TDataStd_Name) aName;
422 if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
423 TCollection_ExtendedString EName = aName->Get();
424 if(S.ShapeType()==TopAbs_SOLID) {
426 SolidSeqN.Append(aName->Get());
428 else if(S.ShapeType()==TopAbs_FACE) {
430 FaceSeqN.Append(aName->Get());
432 else if(S.ShapeType()==TopAbs_EDGE) {
434 EdgeSeqN.Append(aName->Get());
436 else if(S.ShapeType()==TopAbs_VERTEX) {
438 VertSeqN.Append(aName->Get());
443 TopTools_IndexedMapOfShape anIndices;
444 TopExp::MapShapes(MainSh, anIndices);
446 CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
447 "Group_Of_Named_Solids", aResList);
449 CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
450 "Group_Of_Named_Faces", aResList);
452 CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
453 "Group_Of_Named_Edges", aResList);
455 CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
456 "Group_Of_Named_Vertices", aResList);
458 return aResList._retn();
462 //============================================================================
464 // purpose : save OCAF/Geom document
465 //============================================================================
466 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
469 SALOMEDS::TMPFile_var aStreamFile;
470 // Get a temporary directory to store a file
471 std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
473 // OCCT BUG: cannot save a document (in current folder)
474 // if directory name is empty
475 if (aTmpDir.size() == 0) {
483 // Create a list to store names of created files
484 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
486 // Prepare a file name to open
487 TCollection_AsciiString aNameWithExt("");
489 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
490 (theComponent->GetStudy()->URL())).c_str());
491 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
492 aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
493 // Build a full file name of temporary file
494 TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
495 // Save GEOM component in this file
496 _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
497 // Conver a file to the byte stream
498 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
499 // Remove the created file and tmp directory
500 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
502 // Return the created byte stream
503 return aStreamFile._retn();
507 //============================================================================
508 // function : SaveASCII()
510 //============================================================================
511 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
514 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
515 return aStreamFile._retn();
519 //============================================================================
522 //============================================================================
523 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
524 const SALOMEDS::TMPFile& theStream,
528 if (theStream.length() <= 9) {
529 MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
533 // Get a temporary directory for a file
534 std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
536 // OCCT BUG: cannot load a document (from current folder)
537 // if directory name is empty
538 if (aTmpDir.size() == 0) {
546 // Conver the byte stream theStream to a file and place it in tmp directory
547 SALOMEDS::ListOfFileNames_var aSeq =
548 SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
550 // Prepare a file name to open
551 TCollection_AsciiString aNameWithExt("");
553 aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
554 (theComponent->GetStudy()->URL())).c_str());
555 aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
556 TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
559 if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
561 // Remove the created file and tmp directory
562 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
564 SALOMEDS::Study_var Study = theComponent->GetStudy();
565 TCollection_AsciiString name (Study->Name());
571 //============================================================================
572 // function : LoadASCII()
574 //============================================================================
575 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
576 const SALOMEDS::TMPFile& theStream,
579 return Load(theComponent, theStream, theURL, isMultiFile);
583 //============================================================================
584 // function : Close()
586 //============================================================================
587 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
589 _impl->Close(theComponent->GetStudy()->StudyId());
592 //============================================================================
593 // function : CanCopy()
595 //============================================================================
596 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
597 // Try to retrieve known by Geometry component GEOM_Object by given IOR
598 SALOMEDS::GenericAttribute_var anAttr;
599 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
601 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
603 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
604 // If the object is null one it can't be copied: return false
605 if (anObject->_is_nil()) return false;
609 //============================================================================
610 // function : CopyFrom()
612 //============================================================================
613 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
615 // Declare a sequence of the byte to store the copied object
616 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
618 // Try to get GEOM_Object object by given SObject
619 SALOMEDS::GenericAttribute_var anAttr;
620 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
621 GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
622 (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
623 if (anObject->_is_nil()) return aStreamFile._retn();
625 aStreamFile = anObject->GetShapeStream();
627 // Assign an ID the type of GEOM_Object
628 theObjectID = anObject->GetType();
630 // Return created TMPFile
631 return aStreamFile._retn();
634 //============================================================================
635 // function : CanPaste()
637 //============================================================================
638 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
639 // The Geometry component can paste only objects copied by Geometry component
640 // and with the object type = 1
641 if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
645 //============================================================================
646 // function : PasteInto()
648 //============================================================================
649 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
650 CORBA::Long theObjectID,
651 SALOMEDS::SObject_ptr theObject) {
652 // Find the current Study and StudyBuilder
653 SALOMEDS::Study_var aStudy = theObject->GetStudy();
654 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
656 // Retrieve a TopoDS_Shape from byte stream
657 TopoDS_Shape aTopology;
658 istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
659 BRep_Builder aBuilder;
661 BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
662 } catch (Standard_Failure) {
666 // SObject of the created shape is theObject or new Child of Component if theObject == geom component
667 SALOMEDS::SObject_var aNewSO;
668 if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
669 aNewSO = aStudyBuilder->NewObject(theObject);
670 } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
673 //Create a new GEOM_Object
674 Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
675 Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
676 aFunction->SetValue(aTopology);
678 TCollection_AsciiString anEntry;
679 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
680 GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
682 //Set the study entry of the published GEOM_Object
683 obj->SetStudyEntry(aNewSO->GetID());
685 // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
686 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
687 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
688 CORBA::String_var objStr = _orb->object_to_string(obj);
689 anIOR->SetValue(objStr.in());
691 // Return the created in the Study SObject
692 return aNewSO._retn();
695 //============================================================================
696 // function : ComponentDataType()
698 //============================================================================
699 char* GEOM_Gen_i::ComponentDataType()
701 return CORBA::string_dup("GEOM");
704 //============================================================================
705 // function : AddInStudy
707 //============================================================================
708 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
709 GEOM::GEOM_Object_ptr theObject,
711 GEOM::GEOM_Object_ptr theFather)
713 SALOMEDS::SObject_var aResultSO;
714 if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
716 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
717 CORBA::String_var IOR;
719 if(!theFather->_is_nil()) {
720 IOR = _orb->object_to_string(theFather);
721 SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
722 if(aFatherSO->_is_nil()) return aResultSO._retn();
723 aResultSO = aStudyBuilder->NewObject(aFatherSO);
724 //aStudyBuilder->Addreference(aResultSO, aResultSO);
727 aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
728 if(aResultSO->_is_nil()) return aResultSO._retn();
730 GEOM::ListOfGO_var aList = theObject->GetDependency();
731 Standard_Integer aLength = aList->length();
732 if(aLength < 1) return aResultSO._retn();
734 //Publish the arguments
735 for(Standard_Integer i = 0; i< aLength; i++) {
736 GEOM::GEOM_Object_var anObject = aList[i];
737 if(anObject->_is_nil()) continue;
738 IOR = _orb->object_to_string(anObject);
739 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(IOR.in());
740 if(aSO->_is_nil()) continue;
741 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
742 aStudyBuilder->Addreference(aSubSO, aSO);
745 return aResultSO._retn();
748 //============================================================================
749 // function : RestoreSubShapesO
750 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
751 // To be used from python scripts out of geompy.addToStudy (non-default usage)
752 //============================================================================
753 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr theStudy,
754 GEOM::GEOM_Object_ptr theObject,
755 const GEOM::ListOfGO& theArgs,
756 GEOM::find_shape_method theFindMethod,
757 CORBA::Boolean theInheritFirstArg)
759 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
762 // find SObject in the study
763 CORBA::String_var anIORo = _orb->object_to_string(theObject);
764 SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
765 if (CORBA::is_nil(aSO))
768 return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
771 //============================================================================
772 // function : RestoreSubShapesSO
773 // purpose : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
774 // To be used from GUI and from geompy.addToStudy
775 //============================================================================
776 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr theStudy,
777 SALOMEDS::SObject_ptr theSObject,
778 const GEOM::ListOfGO& theArgs,
779 GEOM::find_shape_method theFindMethod,
780 CORBA::Boolean theInheritFirstArg)
782 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
785 SALOMEDS::GenericAttribute_var anAttr;
786 if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
789 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
790 CORBA::String_var anIORso = anAttrIOR->Value();
792 // get Object from SObject
793 GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
794 if (CORBA::is_nil(anO))
797 return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
800 //============================================================================
801 // function : RestoreSubShapes
802 // purpose : Private method. Works only if both theObject and theSObject
803 // are defined, and does not check, if they correspond to each other.
804 //============================================================================
805 CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr theStudy,
806 GEOM::GEOM_Object_ptr theObject,
807 SALOMEDS::SObject_ptr theSObject,
808 const GEOM::ListOfGO& theArgs,
809 GEOM::find_shape_method theFindMethod,
810 CORBA::Boolean theInheritFirstArg)
812 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject))
815 // Arguments to be published
816 GEOM::ListOfGO_var aList;
818 // If theArgs list is empty, we try to publish all arguments,
819 // otherwise publish only passed args
820 Standard_Integer nbArgsActual = -1; // -1 means unknown
821 Standard_Integer aLength = theArgs.length();
823 aList = new GEOM::ListOfGO;
824 aList->length(aLength);
825 for (int i = 0; i < aLength; i++) {
826 aList[i] = theArgs[i];
831 aList = theObject->GetDependency();
832 aLength = aList->length();
833 nbArgsActual = aLength;
839 if (theInheritFirstArg || (nbArgsActual == 1)) {
840 // Do not publish argument's reflection,
841 // but only reconstruct its published sub-shapes
843 GEOM::GEOM_Object_var anArgO = aList[0];
844 CORBA::String_var anIOR = _orb->object_to_string(anArgO);
845 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
847 GEOM::ListOfGO_var aParts =
848 RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
850 // set the color of the transformed shape to the color of initial shape
851 theObject->SetColor(aList[0]->GetColor());
853 return (aParts->length() > 0);
856 // Get interface, containing method, which we will use to reconstruct sub-shapes
857 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
858 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
860 // Reconstruct arguments and tree of sub-shapes of the arguments
861 CORBA::String_var anIOR;
862 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
863 for (Standard_Integer i = 0; i < aLength; i++)
865 GEOM::GEOM_Object_var anArgO = aList[i];
866 if (!CORBA::is_nil(anArgO)) {
867 anIOR = _orb->object_to_string(anArgO);
868 SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
869 TCollection_AsciiString anArgName;
870 if (CORBA::is_nil(anArgSO)) {
872 anArgName += TCollection_AsciiString(i);
875 anArgName = anArgSO->GetName();
878 // Find a sub-shape of theObject in place of the argument
879 GEOM::GEOM_Object_var aSubO;
880 switch (theFindMethod) {
881 case GEOM::FSM_GetInPlace:
884 aSubO = aShapesOp->GetInPlace(theObject, anArgO);
887 case GEOM::FSM_Transformed:
889 // transformation, cannot use GetInPlace, operate with indices
890 GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
891 if (anIDs->length() > 1) {
893 aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
894 if (!CORBA::is_nil(aSubO))
895 aGroupOp->UnionIDs(aSubO, anIDs);
899 aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
903 case GEOM::FSM_GetSame:
906 aSubO = aShapesOp->GetSame(theObject, anArgO);
909 case GEOM::FSM_GetShapesOnShape:
911 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
912 aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
913 (short)GEOM::SOLID, GEOM::ST_ONIN);
916 case GEOM::FSM_GetInPlaceByHistory:
918 // Use GetInPlaceByHistory
919 aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
926 if (!CORBA::is_nil(aSubO)) {
927 // Publish the sub-shape
928 TCollection_AsciiString aSubName ("from_");
929 aSubName += anArgName;
930 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
931 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
933 aSubO->SetColor(anArgO->GetColor());
935 if (!CORBA::is_nil(anArgSO)) {
936 // Restore published sub-shapes of the argument
937 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
938 // pass theObject, because only it has the history
939 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
941 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
944 else { // GetInPlace failed, try to build from published parts
945 if (!CORBA::is_nil(anArgSO)) {
946 SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
948 // Restore published sub-shapes of the argument
949 GEOM::ListOfGO_var aParts =
950 RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
952 if (aParts->length() > 0) {
953 // try to build an argument from a set of its sub-shapes,
954 // that published and will be reconstructed
955 if (aParts->length() > 1) {
956 aSubO = aShapesOp->MakeCompound(aParts);
961 if (!CORBA::is_nil(aSubO)) {
962 // Publish the sub-shape
963 TCollection_AsciiString aSubName ("from_parts_of_");
964 aSubName += anArgName;
965 aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
967 aSubO->SetColor(anArgO->GetColor());
971 // remove created aSubSO, because no parts have been found
972 aStudyBuilder->RemoveObject(aSubSO);
975 } // try to build from published parts
977 } // process arguments
982 //============================================================================
983 // function : RestoreSubShapesOneLevel
984 // purpose : Private method
985 //============================================================================
986 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr theStudy,
987 SALOMEDS::SObject_ptr theOldSO,
988 SALOMEDS::SObject_ptr theNewSO,
989 GEOM::GEOM_Object_ptr theNewO,
990 GEOM::find_shape_method theFindMethod)
993 GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
994 if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
995 CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO))
996 return aParts._retn();
998 SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1000 // Get interface, containing method, which we will use to reconstruct sub-shapes
1001 GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1002 GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId());
1004 // Reconstruct published sub-shapes
1005 SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1008 for (it->Init(); it->More(); it->Next()) {
1011 aParts->length(aLen);
1013 for (it->Init(); it->More(); it->Next()) {
1014 SALOMEDS::SObject_var anOldSubSO = it->Value();
1016 TCollection_AsciiString anArgName = anOldSubSO->GetName();
1018 SALOMEDS::GenericAttribute_var anAttr;
1019 if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1020 SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1021 GEOM::GEOM_Object_var anOldSubO =
1022 GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1023 if (!CORBA::is_nil(anOldSubO)) {
1024 // Find a sub-shape of theNewO in place of anOldSubO
1025 GEOM::GEOM_Object_var aNewSubO;
1026 switch (theFindMethod) {
1027 case GEOM::FSM_GetInPlace:
1030 aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1033 case GEOM::FSM_Transformed:
1035 // transformation, cannot use GetInPlace, operate with indices
1036 GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1037 if (anIDs->length() > 1) {
1039 aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1040 if (!CORBA::is_nil(aNewSubO))
1041 aGroupOp->UnionIDs(aNewSubO, anIDs);
1045 aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1049 case GEOM::FSM_GetSame:
1052 aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1055 case GEOM::FSM_GetShapesOnShape:
1057 // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1058 aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1059 (short)GEOM::SOLID, GEOM::ST_ONIN);
1062 case GEOM::FSM_GetInPlaceByHistory:
1064 // Use GetInPlaceByHistory
1065 aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1072 if (!CORBA::is_nil(aNewSubO)) {
1073 // add the part to the list
1074 aParts[i] = aNewSubO;
1077 // Publish the sub-shape
1078 TCollection_AsciiString aSubName ("from_");
1079 aSubName += anArgName;
1080 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1081 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1083 aNewSubO->SetColor(anOldSubO->GetColor());
1085 // Restore published sub-shapes of the argument
1086 if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1087 // pass the main shape as Object, because only it has the history
1088 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1090 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
1092 else { // GetInPlace failed, try to build from published parts
1093 SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1095 // Restore published sub-shapes of the argument
1096 GEOM::ListOfGO_var aParts =
1097 RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1099 if (aParts->length() > 0) {
1100 // try to build an object from a set of its sub-shapes,
1101 // that published and will be reconstructed
1102 if (aParts->length() > 1) {
1103 aNewSubO = aShapesOp->MakeCompound(aParts);
1106 aNewSubO = aParts[0];
1109 if (!CORBA::is_nil(aNewSubO)) {
1110 // add the part to the list
1111 aParts[i] = aNewSubO;
1114 // Publish the sub-shape
1115 TCollection_AsciiString aSubName = "from_parts_of_";
1116 aSubName += anArgName;
1117 aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1119 aNewSubO->SetColor(anOldSubO->GetColor());
1123 // remove created aSubSO, because no parts have been found
1124 aStudyBuilder->RemoveObject(aNewSubSO);
1126 } // try to build from published parts
1129 } // iterate on published sub-shapes
1132 return aParts._retn();
1135 //============================================================================
1136 // function : register()
1137 // purpose : register 'name' in 'name_service'
1138 //============================================================================
1139 void GEOM_Gen_i::register_name(char * name)
1141 GEOM::GEOM_Gen_var g = _this();
1142 name_service->Register(g, name);
1145 //============================================================================
1148 //============================================================================
1149 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
1151 _impl->Undo(theStudyID);
1154 //============================================================================
1157 //============================================================================
1158 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
1160 _impl->Redo(theStudyID);
1163 //============================================================================
1164 // function : GetIBasicOperations
1166 //============================================================================
1167 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1168 throw ( SALOME::SALOME_Exception )
1170 Unexpect aCatch(SALOME_SalomeException);
1171 MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1173 GEOM::GEOM_Gen_ptr engine = _this();
1175 //transfer reference on engine
1176 GEOM_IBasicOperations_i* aServant =
1177 new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1179 // activate the CORBA servant
1180 GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1181 return operations._retn();
1184 //============================================================================
1185 // function : GetITransformOperations
1187 //============================================================================
1188 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1189 throw ( SALOME::SALOME_Exception )
1191 Unexpect aCatch(SALOME_SalomeException);
1192 MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1194 GEOM::GEOM_Gen_ptr engine = _this();
1196 GEOM_ITransformOperations_i* aServant =
1197 new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1199 // activate the CORBA servant
1200 GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1201 return operations._retn();
1204 //============================================================================
1205 // function : GetI3DPrimOperations
1207 //============================================================================
1208 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1209 throw ( SALOME::SALOME_Exception )
1211 Unexpect aCatch(SALOME_SalomeException);
1212 MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1214 GEOM::GEOM_Gen_ptr engine = _this();
1216 GEOM_I3DPrimOperations_i* aServant =
1217 new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1219 // activate the CORBA servant
1220 GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1221 return operations._retn();
1224 //============================================================================
1225 // function : GetIShapesOperations
1227 //============================================================================
1228 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1229 throw ( SALOME::SALOME_Exception )
1231 Unexpect aCatch(SALOME_SalomeException);
1232 MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1234 GEOM::GEOM_Gen_ptr engine = _this();
1236 GEOM_IShapesOperations_i* aServant =
1237 new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1239 // activate the CORBA servant
1240 GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1241 return operations._retn();
1244 //============================================================================
1245 // function : GetIBlocksOperations
1247 //============================================================================
1248 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1249 throw ( SALOME::SALOME_Exception )
1251 Unexpect aCatch(SALOME_SalomeException);
1252 MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1254 GEOM::GEOM_Gen_ptr engine = _this();
1256 GEOM_IBlocksOperations_i* aServant =
1257 new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1259 // activate the CORBA servant
1260 GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1261 return operations._retn();
1264 //============================================================================
1265 // function : GetIBooleanOperations
1267 //============================================================================
1268 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1269 throw ( SALOME::SALOME_Exception )
1271 Unexpect aCatch(SALOME_SalomeException);
1272 MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1274 GEOM::GEOM_Gen_ptr engine = _this();
1276 GEOM_IBooleanOperations_i* aServant =
1277 new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1279 // activate the CORBA servant
1280 GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1281 return operations._retn();
1284 //============================================================================
1285 // function : GetICurvesOperations
1287 //============================================================================
1288 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1289 throw ( SALOME::SALOME_Exception )
1291 Unexpect aCatch(SALOME_SalomeException);
1292 MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1294 GEOM::GEOM_Gen_ptr engine = _this();
1296 GEOM_ICurvesOperations_i* aServant =
1297 new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1299 // activate the CORBA servant
1300 GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1301 return operations._retn();
1304 //============================================================================
1305 // function : GetILocalOperations
1307 //============================================================================
1308 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1309 throw ( SALOME::SALOME_Exception )
1311 Unexpect aCatch(SALOME_SalomeException);
1312 MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1314 GEOM::GEOM_Gen_ptr engine = _this();
1316 GEOM_ILocalOperations_i* aServant =
1317 new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1319 // activate the CORBA servant
1320 GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1321 return operations._retn();
1324 //============================================================================
1325 // function : GetIHealingOperations
1327 //============================================================================
1328 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1329 throw ( SALOME::SALOME_Exception )
1331 Unexpect aCatch(SALOME_SalomeException);
1332 MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1334 GEOM::GEOM_Gen_ptr engine = _this();
1336 GEOM_IHealingOperations_i* aServant =
1337 new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1339 // activate the CORBA servant
1340 GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1341 return operations._retn();
1344 //============================================================================
1345 // function : GetIInsertOperations
1347 //============================================================================
1348 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1349 throw ( SALOME::SALOME_Exception )
1351 Unexpect aCatch(SALOME_SalomeException);
1352 MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1354 GEOM::GEOM_Gen_ptr engine = _this();
1356 GEOM_IInsertOperations_i* aServant =
1357 new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1359 // activate the CORBA servant
1360 GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1361 return operations._retn();
1364 //============================================================================
1365 // function : GetIMeasureOperations
1367 //============================================================================
1368 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1369 throw ( SALOME::SALOME_Exception )
1371 Unexpect aCatch(SALOME_SalomeException);
1372 MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1374 GEOM::GEOM_Gen_ptr engine = _this();
1376 GEOM_IMeasureOperations_i* aServant =
1377 new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1379 // activate the CORBA servant
1380 GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1381 return operations._retn();
1384 //============================================================================
1385 // function : GetIGroupOperations
1387 //============================================================================
1388 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1389 throw ( SALOME::SALOME_Exception )
1391 Unexpect aCatch(SALOME_SalomeException);
1392 MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1394 GEOM::GEOM_Gen_ptr engine = _this();
1396 GEOM_IGroupOperations_i* aServant =
1397 new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1399 // activate the CORBA servant
1400 GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1401 return operations._retn();
1404 //=============================================================================
1408 //=============================================================================
1409 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1410 const GEOM::ListOfLong& theIndices)
1412 if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1413 return GEOM::GEOM_Object::_nil();
1414 CORBA::String_var entry = theMainShape->GetEntry();
1415 Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1416 if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1418 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1419 for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1421 Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1422 if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1424 TCollection_AsciiString anEntry;
1425 TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1426 return GetObject(anObject->GetDocID(), anEntry.ToCString());
1429 //=============================================================================
1433 //=============================================================================
1434 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1436 CORBA::String_var anEntry = theObject->GetEntry();
1437 Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1438 if (anObject.IsNull()) return;
1439 _impl->RemoveObject(anObject);
1444 //=================================================================================
1445 // function : GetStringFromIOR()
1446 // purpose : returns a string that represents a 'GEOM::GEOM_Object_var'
1447 //=================================================================================
1448 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1449 return _orb->object_to_string(theObject);
1453 //=================================================================================
1454 // function : GetIORFromString()
1455 // purpose : returns a 'GEOM::GEOM_Object_var' from a string representing it
1456 //=================================================================================
1457 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1458 GEOM::GEOM_Object_var aGeomObject;
1459 if(strcmp(stringIOR,"") != 0){
1460 CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1461 if(!CORBA::is_nil(anObject))
1462 aGeomObject = GEOM::GEOM_Object::_narrow(anObject.in());
1464 return aGeomObject._retn();
1467 //=================================================================================
1468 // function : GetObject()
1470 //=================================================================================
1471 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1473 GEOM::GEOM_Object_var obj;
1474 Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1475 if (handle_object.IsNull()) return obj._retn();
1477 TCollection_AsciiString stringIOR = handle_object->GetIOR();
1478 if (stringIOR.Length() > 1) {
1479 CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1480 if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1484 GEOM::GEOM_Gen_ptr engine = _this();
1485 GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1487 obj = servant->_this();
1488 CORBA::String_var objStr = _orb->object_to_string(obj);
1489 TCollection_AsciiString anAscii( (char *)objStr.in() );
1490 handle_object->SetIOR( anAscii );
1494 //=================================================================================
1495 // function : hasObjectInfo()
1496 // purpose : shows if module provides information for its objects
1497 //=================================================================================
1498 bool GEOM_Gen_i::hasObjectInfo()
1503 //=================================================================================
1504 // function : getObjectInfo()
1505 // purpose : returns an information for a given object by its entry
1506 //=================================================================================
1507 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1509 GEOM::GEOM_Object_var aGeomObject;
1511 CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1512 SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1513 SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1514 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1515 SALOMEDS::SObject_var aResultSObj;
1516 if (aSObj->ReferencedObject(aResultSObj))
1517 aSObj = aResultSObj;
1519 SALOMEDS::GenericAttribute_var anAttr;
1520 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1521 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1522 CORBA::String_var aVal = anIOR->Value();
1523 CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1524 aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1527 const char* aTypeInfo = "Object";
1528 if ( !aGeomObject->_is_nil() ) {
1529 GEOM::GEOM_IKindOfShape::shape_kind aKind;
1530 GEOM::ListOfLong_var anInts;
1531 GEOM::ListOfDouble_var aDbls;
1533 GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1534 aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1536 if ( anOp->IsDone() ) {
1538 case GEOM::GEOM_IKindOfShape::COMPOUND:
1539 aTypeInfo = "Compound";
1541 case GEOM::GEOM_IKindOfShape::COMPSOLID:
1542 aTypeInfo = "CompSolid";
1544 case GEOM::GEOM_IKindOfShape::SHELL:
1545 aTypeInfo = "Shell";
1547 case GEOM::GEOM_IKindOfShape::WIRE:
1548 if ( anInts[0] == 1 )
1549 aTypeInfo = "Closed Wire";
1550 else if ( anInts[0] == 2 )
1551 aTypeInfo = "Opened Wire";
1556 case GEOM::GEOM_IKindOfShape::SPHERE:
1557 aTypeInfo = "Sphere";
1559 case GEOM::GEOM_IKindOfShape::CYLINDER:
1560 aTypeInfo = "Cylinder";
1562 case GEOM::GEOM_IKindOfShape::BOX:
1563 case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1566 case GEOM::GEOM_IKindOfShape::TORUS:
1567 aTypeInfo = "Torus";
1569 case GEOM::GEOM_IKindOfShape::CONE:
1572 case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1573 aTypeInfo = "Polyhedron";
1575 case GEOM::GEOM_IKindOfShape::SOLID:
1576 aTypeInfo = "Solid";
1579 case GEOM::GEOM_IKindOfShape::SPHERE2D:
1580 aTypeInfo = "Spherical Face";
1582 case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1583 aTypeInfo = "Cylindrical Face";
1585 case GEOM::GEOM_IKindOfShape::TORUS2D:
1586 aTypeInfo = "Toroidal Face";
1588 case GEOM::GEOM_IKindOfShape::CONE2D:
1589 aTypeInfo = "Conical Face";
1591 case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1594 case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1595 aTypeInfo = "Elliptical Face";
1597 case GEOM::GEOM_IKindOfShape::POLYGON:
1598 aTypeInfo = "Polygon";
1600 case GEOM::GEOM_IKindOfShape::PLANE:
1601 aTypeInfo = "Plane";
1603 case GEOM::GEOM_IKindOfShape::PLANAR:
1604 aTypeInfo = "Planar Face";
1606 case GEOM::GEOM_IKindOfShape::FACE:
1610 case GEOM::GEOM_IKindOfShape::CIRCLE:
1611 aTypeInfo = "Circle";
1613 case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1616 case GEOM::GEOM_IKindOfShape::ELLIPSE:
1617 aTypeInfo = "Ellipse";
1619 case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1620 aTypeInfo = "Arc Ellipse";
1622 case GEOM::GEOM_IKindOfShape::LINE:
1625 case GEOM::GEOM_IKindOfShape::SEGMENT:
1626 aTypeInfo = "Segment";
1628 case GEOM::GEOM_IKindOfShape::EDGE:
1631 case GEOM::GEOM_IKindOfShape::VERTEX:
1632 aTypeInfo = "Vertex";
1640 char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1641 sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1643 char* ret = CORBA::string_dup(anInfo);
1648 //=====================================================================================
1650 //=====================================================================================
1654 PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1655 PortableServer::POA_ptr poa,
1656 PortableServer::ObjectId * contId,
1657 const char *instanceName,
1658 const char * interfaceName)
1660 GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1661 // Don't understand the reason of this register ????
1662 // myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1663 return myGEOM_Gen_i->getId();