_UndoLimit = 10;
}
+/*!
+ * Destructor
+ */
+GEOM_Engine::~GEOM_Engine()
+{
+ GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It(_objects);
+ for(; It.More(); It.Next())
+ {
+ RemoveObject(Handle(GEOM_Object)::DownCast(It.Value()));
+ }
+
+ //Close all documents not closed
+ for(Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr(_mapIDDocument); anItr.More(); anItr.Next())
+ Close(anItr.Key());
+
+ _mapIDDocument.Clear();
+ _objects.Clear();
+}
+
//=============================================================================
/*!
* GetDocument
//=============================================================================
Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType)
{
- Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
- Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
+ Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
+ Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
- TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
- Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
+ // NPAL18604: use existing label to decrease memory usage,
+ // if this label has been freed (object deleted)
+ bool useExisting = false;
+ TDF_Label aChild;
+ if (!_lastCleared.IsNull()) {
+ if (_lastCleared.Root() == aDoc->Main().Root()) {
+ useExisting = true;
+ aChild = _lastCleared;
+ _lastCleared.Nullify();
+ }
+ }
+ if (!useExisting) {
+ // create new label
+ aChild = TDF_TagSource::NewChild(aDoc->Main());
+ }
+
+ Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
- //Put an object in the map of created objects
- TCollection_AsciiString anID = BuildIDFromObject(anObject);
- if(_objects.IsBound(anID)) _objects.UnBind(anID);
- _objects.Bind(anID, anObject);
+ //Put an object in the map of created objects
+ TCollection_AsciiString anID = BuildIDFromObject(anObject);
+ if(_objects.IsBound(anID)) _objects.UnBind(anID);
+ _objects.Bind(anID, anObject);
- return anObject;
+ return anObject;
}
//=============================================================================
Handle(TDocStd_Document) aDoc = GetDocument(theMainShape->GetDocID());
Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
- TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main());
+ // NPAL18604: use existing label to decrease memory usage,
+ // if this label has been freed (object deleted)
+ bool useExisting = false;
+ TDF_Label aChild;
+ if (!_lastCleared.IsNull()) {
+ if (_lastCleared.Root() == aDoc->Main().Root()) {
+ useExisting = true;
+ aChild = _lastCleared;
+ _lastCleared.Nullify();
+ }
+ }
+ if (!useExisting) {
+ // create new label
+ aChild = TDF_TagSource::NewChild(aDoc->Main());
+ }
Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction();
Handle(GEOM_Object) anObject = new GEOM_Object(aChild, 28); //28 is SUBSHAPE type
//=============================================================================
bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject)
{
- if(!theObject) return false;
+ if (!theObject) return false;
//Remove an object from the map of available objects
TCollection_AsciiString anID = BuildIDFromObject(theObject);
- if(_objects.IsBound(anID)) _objects.UnBind(anID);
+ if (_objects.IsBound(anID)) _objects.UnBind(anID);
int nb = theObject->GetNbFunctions();
Handle(TDataStd_TreeNode) aNode;
- for(int i = 1; i<=nb; i++) {
+ for (int i = 1; i<=nb; i++) {
Handle(GEOM_Function) aFunction = theObject->GetFunction(i);
- if(aFunction->GetEntry().FindAttribute(GEOM_Function::GetFunctionTreeID(), aNode))
+ if (aFunction->GetEntry().FindAttribute(GEOM_Function::GetFunctionTreeID(), aNode))
aNode->Remove();
}
TDF_Label aLabel = theObject->GetEntry();
aLabel.ForgetAllAttributes(Standard_True);
+ _lastCleared = aLabel;
theObject.Nullify();
//=============================================================================
void GEOM_Engine::Close(int theDocID)
{
- if(_mapIDDocument.IsBound(theDocID)) {
+ if (_mapIDDocument.IsBound(theDocID)) {
Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
//Remove all GEOM Objects associated to the given document
TColStd_SequenceOfAsciiString aSeq;
- GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It(_objects);
- for(; It.More(); It.Next()) {
- TCollection_AsciiString anObjID(It.Key());
+ GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It (_objects);
+ for (; It.More(); It.Next()) {
+ TCollection_AsciiString anObjID (It.Key());
Standard_Integer anID = ExtractDocID(anObjID);
- if(theDocID == anID) aSeq.Append(It.Key());
+ if (theDocID == anID) aSeq.Append(It.Key());
}
- for(Standard_Integer i=1; i<=aSeq.Length(); i++) _objects.UnBind(aSeq.Value(i));
+ for (Standard_Integer i=1; i<=aSeq.Length(); i++) _objects.UnBind(aSeq.Value(i));
+
+ _lastCleared.Nullify();
- _mapIDDocument.UnBind(theDocID);
+ _mapIDDocument.UnBind(theDocID);
_OCAFApp->Close(aDoc);
aDoc.Nullify();
}
* DumpPython
*/
//=============================================================================
-TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
+TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
- bool isPublished,
+ bool isPublished,
bool& aValidScript)
{
TCollection_AsciiString aScript;
Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
-
- if(aDoc.IsNull()) return TCollection_AsciiString("def RebuildData(theStudy): pass\n");
-
+
+ if (aDoc.IsNull()) return TCollection_AsciiString("def RebuildData(theStudy): pass\n");
+
aScript = "import geompy\n";
- aScript += "import math\n\n";
+ aScript += "import math\n";
+ aScript += "import SALOMEDS\n\n";
aScript += "def RebuildData(theStudy):";
aScript += "\n\tgeompy.init_geom(theStudy)";
-
+
Standard_Integer posToInertGlobalVars = aScript.Length() + 1;
Handle(TDataStd_TreeNode) aNode, aRoot;
Handle(GEOM_Function) aFunction;
TColStd_MapOfTransient aMap;
- if(aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
+ if (aDoc->Main().FindAttribute(GEOM_Function::GetFunctionTreeID(), aRoot)) {
TDataStd_ChildNodeIterator Itr(aRoot);
- for(; Itr.More(); Itr.Next()) {
+ for (; Itr.More(); Itr.Next()) {
aNode = Itr.Value();
aFunction = GEOM_Function::GetFunction(aNode->Label());
- if(aFunction.IsNull()) {
- cout << "Null function !!!!" << endl;
+ if (aFunction.IsNull()) {
+ MESSAGE ( "Null function !!!!" );
continue;
}
ProcessFunction(aFunction, aScript, aMap);
//Replace entries by the names
TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"),
allowedChars ("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
- if(aLen == 0) anUpdatedScript = aScript;
+ if (aLen == 0) anUpdatedScript = aScript;
- for(Standard_Integer i = 1; i <= aLen; i+=2) {
+ for (Standard_Integer i = 1; i <= aLen; i+=2) {
anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i)-1);
anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i+1));
- if(theObjectNames.IsBound(anEntry)) {
+ if (theObjectNames.IsBound(anEntry)) {
aName = theObjectNames.Find(anEntry);
// check validity of aName
bool isValidName = true;
}
//Add final part of the script
- if(aLen && aSeq->Value(aLen) < aScriptLength) anUpdatedScript += aScript.SubString(aSeq->Value(aLen)+1, aScriptLength); // mkr : IPAL11865
-
+ if (aLen && aSeq->Value(aLen) < aScriptLength)
+ anUpdatedScript += aScript.SubString(aSeq->Value(aLen)+1, aScriptLength); // mkr : IPAL11865
+
+ // ouv : NPAL12872
+ for (anEntryToNameIt.Initialize( theObjectNames );
+ anEntryToNameIt.More();
+ anEntryToNameIt.Next())
+ {
+ const TCollection_AsciiString& aEntry = anEntryToNameIt.Key();
+ const TCollection_AsciiString& aName = anEntryToNameIt.Value();
+
+ TDF_Label L;
+ TDF_Tool::Label( aDoc->GetData(), aEntry, L );
+ if ( L.IsNull() )
+ continue;
+
+ Handle(GEOM_Object) obj = GEOM_Object::GetObject( L );
+ if ( obj.IsNull() )
+ continue;
+
+ bool anAutoColor = obj->GetAutoColor();
+ if ( anAutoColor )
+ {
+ TCollection_AsciiString aCommand( "\n\t" );
+ aCommand += aName + ".SetAutoColor(1)";
+ anUpdatedScript += aCommand.ToCString();
+ }
+
+ SALOMEDS::Color aColor = obj->GetColor();
+ if ( aColor.R > 0 || aColor.G > 0 || aColor.B > 0 )
+ {
+ TCollection_AsciiString aCommand( "\n\t" );
+ aCommand += aName + ".SetColor(SALOMEDS.Color(" + aColor.R + "," + aColor.G + "," + aColor.B + "))";
+ anUpdatedScript += aCommand.ToCString();
+ }
+ }
+
// Make script to publish in study
if ( isPublished )
{
- map< int, string > anEntryToCommandMap; // sort publishing commands by object entry
+ std::map< int, std::string > anEntryToCommandMap; // sort publishing commands by object entry
for (anEntryToNameIt.Initialize( theObjectNames );
anEntryToNameIt.More();
anEntryToNameIt.Next())
// bind a command to the last digit of the entry
int tag =
aEntry.SubString( aEntry.SearchFromEnd(":")+1, aEntry.Length() ).IntegerValue();
- anEntryToCommandMap.insert( make_pair( tag, aCommand.ToCString() ));
+ anEntryToCommandMap.insert( std::make_pair( tag, aCommand.ToCString() ));
}
// add publishing commands to the script
- map< int, string >::iterator anEntryToCommand = anEntryToCommandMap.begin();
+ std::map< int, std::string >::iterator anEntryToCommand = anEntryToCommandMap.begin();
for ( ; anEntryToCommand != anEntryToCommandMap.end(); ++anEntryToCommand ) {
anUpdatedScript += (char*)anEntryToCommand->second.c_str();
}
}
- anUpdatedScript += "\n\tpass\n";
+ //anUpdatedScript += "\n\tpass\n";
+ anUpdatedScript += "\n";
aValidScript = true;
// fill _studyEntry2NameMap and build globalVars
globalVars.Insert( 1, "\n\tglobal " );
anUpdatedScript.Insert( posToInertGlobalVars, globalVars );
}
-
+
return anUpdatedScript;
}
Standard_Integer aLen = theString.Length();
Standard_Boolean isFound = Standard_False;
- char* arr = theString.ToCString();
+ const char* arr = theString.ToCString();
Standard_Integer i = 0, j;
while(i < aLen) {