-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifdef WNT
+#ifdef WIN32
#pragma warning( disable:4786 )
#endif
#include "GEOM_Engine.hxx"
-#include "GEOM_Solver.hxx"
+#include "GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient.hxx"
+#include "GEOM_Field.hxx"
#include "GEOM_Function.hxx"
#include "GEOM_ISubShape.hxx"
-#include "GEOM_SubShapeDriver.hxx"
-#include "GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient.hxx"
#include "GEOM_PythonDump.hxx"
+#include "GEOM_Solver.hxx"
+#include "GEOM_SubShapeDriver.hxx"
#include "Sketcher_Profile.hxx"
#include <Basics_OCCTVersion.hxx>
#include <TColStd_MapOfTransient.hxx>
#include <TColStd_HSequenceOfInteger.hxx>
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
#include <TColStd_HArray1OfByte.hxx>
#include <TColStd_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
-#else
-#include <TDataStd_HArray1OfByte.hxx>
-#include <Interface_DataMapIteratorOfDataMapOfIntegerTransient.hxx>
-#endif
#include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
static GEOM_Engine* TheEngine = NULL;
-static TCollection_AsciiString BuildIDFromObject(Handle(GEOM_Object)& theObject)
+static TCollection_AsciiString BuildIDFromObject(Handle(GEOM_BaseObject)& theObject)
{
TCollection_AsciiString anID(theObject->GetDocID()), anEntry;
TDF_Tool::Entry(theObject->GetEntry(), anEntry);
return anID;
}
-static TCollection_AsciiString BuildID(Standard_Integer theDocID, char* theEntry)
+static TCollection_AsciiString BuildID(Standard_Integer theDocID, const char* theEntry)
{
TCollection_AsciiString anID(theDocID);
anID+=(TCollection_AsciiString("_")+theEntry);
//================================================================================
void GEOM_Engine::healPyName( TCollection_AsciiString& pyName,
- const TCollection_AsciiString& anEntry,
- Resource_DataMapOfAsciiStringAsciiString& aNameToEntry)
+ const TCollection_AsciiString& anEntry,
+ Resource_DataMapOfAsciiStringAsciiString& aNameToEntry)
{
const TCollection_AsciiString allowedChars
("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver());
_OCAFApp = new GEOM_Application();
- _UndoLimit = 10;
+ _UndoLimit = 0;
}
/*!
RemoveObject(*objit);
//Close all documents not closed
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
TColStd_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
-#else
- Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
-#endif
for (; anItr.More(); anItr.Next())
{
Close(anItr.Key());
int GEOM_Engine::GetDocID(Handle(TDocStd_Document) theDocument)
{
if (theDocument.IsNull()) return -1;
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
TColStd_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
-#else
- Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr (_mapIDDocument);
-#endif
for (; anItr.More(); anItr.Next())
if (anItr.Value() == theDocument) return anItr.Key();
* GetObject
*/
//=============================================================================
-Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry, bool force)
+
+Handle(GEOM_BaseObject) GEOM_Engine::GetObject(int theDocID, const char* theEntry, bool force)
{
- Handle(GEOM_Object) anObject;
+ Handle(GEOM_BaseObject) anObject;
TCollection_AsciiString anID = BuildID(theDocID, theEntry);
if (_objects.IsBound(anID)) {
- anObject = Handle(GEOM_Object)::DownCast(_objects(anID));
+ anObject = Handle(GEOM_BaseObject)::DownCast(_objects(anID));
}
else if (force) {
Handle(TDocStd_Document) aDoc = GetDocument(theDocID, force);
if ( !aDoc.IsNull()) {
TDF_Label aLabel;
TDF_Tool::Label(aDoc->Main().Data(), theEntry, aLabel, Standard_True);
- anObject = new GEOM_Object(aLabel);
- _objects.Bind(anID, anObject);
+ if ( !aLabel.IsNull() ) {
+ int objType = GEOM_BaseObject::GetType( aLabel );
+ switch ( objType ) {
+ case GEOM_FIELD_OBJTYPE: anObject = new GEOM_Field (aLabel); break;
+ case GEOM_FIELD_STEP_OBJTYPE: anObject = new GEOM_FieldStep(aLabel); break;
+ default: anObject = new GEOM_Object (aLabel);
+ }
+ _objects.Bind(anID, anObject);
+ }
}
}
//=============================================================================
/*!
- * AddObject
+ * AddBaseObject
*/
//=============================================================================
-Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType)
+
+Handle(GEOM_BaseObject) GEOM_Engine::AddBaseObject(int theDocID, int theType)
{
Handle(TDocStd_Document) aDoc = GetDocument(theDocID);
Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main());
aChild = TDF_TagSource::NewChild(aDoc->Main());
}
- Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType);
+ Handle(GEOM_BaseObject) anObject;
+ switch ( theType ) {
+ case GEOM_FIELD_OBJTYPE: anObject = new GEOM_Field (aChild, theType); break;
+ case GEOM_FIELD_STEP_OBJTYPE: anObject = new GEOM_FieldStep(aChild, theType); break;
+ default: anObject = new GEOM_Object (aChild, theType);
+ }
//Put an object in the map of created objects
TCollection_AsciiString anID = BuildIDFromObject(anObject);
return anObject;
}
+//================================================================================
+/*!
+ * \brief Adds a new object of the type theType in the OCAF document
+ */
+//================================================================================
+
+Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType)
+{
+ return Handle(GEOM_Object)::DownCast( AddBaseObject(theDocID, theType) );
+}
+
//=============================================================================
/*!
* AddSubShape
*/
//=============================================================================
-Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape,
+
+Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape,
Handle(TColStd_HArray1OfInteger) theIndices,
bool isStandaloneOperation)
{
* RemoveObject
*/
//=============================================================================
-bool GEOM_Engine::RemoveObject(Handle(GEOM_Object) theObject)
+bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject)
{
if (theObject.IsNull()) 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)) {
+ Handle(GEOM_BaseObject) anObject = Handle(GEOM_BaseObject)::DownCast(_objects(anID));
+ if ( anObject != theObject )
+ anObject->_label = anObject->_label.Root();
+ _objects.UnBind(anID);
+ }
// If sub-shape, remove it from the list of sub-shapes of its main shape
- if (!theObject->IsMainShape()) {
+ Handle(GEOM_Object) aGO = Handle(GEOM_Object)::DownCast( theObject );
+ if ( !aGO.IsNull() && !aGO->IsMainShape()) {
Handle(GEOM_Function) aFunction = theObject->GetFunction(1);
GEOM_ISubShape aSSI (aFunction);
Handle(GEOM_Function) aMainShape = aSSI.GetMainShape();
// Remember the label to reuse it then
std::list<TDF_Label>& aFreeLabels = _freeLabels[aDocID];
- aFreeLabels.push_back(aLabel);
+ if ( aFreeLabels.empty() || aFreeLabels.back() != aLabel )
+ aFreeLabels.push_back(aLabel);
+
+ // we can't explicitely delete theObject. At least prevent its functioning
+ // as an alive object when aLabel is reused for a new object
+ theObject->_label = aLabel.Root();
+ theObject->_ior.Clear();
+ theObject->_parameters.Clear();
+ theObject->_docID = -1;
theObject.Nullify();
* Save
*/
//=============================================================================
-bool GEOM_Engine::Save(int theDocID, char* theFileName)
+bool GEOM_Engine::Save(int theDocID, const char* theFileName)
{
if(!_mapIDDocument.IsBound(theDocID)) return false;
Handle(TDocStd_Document) aDoc = Handle(TDocStd_Document)::DownCast(_mapIDDocument(theDocID));
* Load
*/
//=============================================================================
-bool GEOM_Engine::Load(int theDocID, char* theFileName)
+bool GEOM_Engine::Load(int theDocID, const char* theFileName)
{
Handle(TDocStd_Document) aDoc;
-#if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
if (_OCAFApp->Open(theFileName, aDoc) != PCDM_RS_OK) {
-#else
- if (_OCAFApp->Open(theFileName, aDoc) != CDF_RS_OK) {
-#endif
return false;
}
TDF_Label L;
TDF_Tool::Label( aDoc->GetData(), data._entry, L );
if ( L.IsNull() ) continue;
- Handle(GEOM_Object) obj = GEOM_Object::GetObject( L );
+ Handle(GEOM_BaseObject) obj = GEOM_BaseObject::GetObject( L );
// fill maps
if ( !obj.IsNull() ) {
TSting2ObjDataMap::iterator ent2Data =
}
}
- // // add commands of folders creation and putting objects into it
- // TCollection_AsciiString createFolderCmd("\n");
- // createFolderCmd += "\t";
- // createFolderCmd += "geompy.CreateFolder(";
- // for (aStEntry2ObjDataPtrIt = aStEntry2ObjDataPtr.begin();
- // aStEntry2ObjDataPtrIt != aStEntry2ObjDataPtr.end();
- // ++aStEntry2ObjDataPtrIt)
- // {
- // const TCollection_AsciiString& studyEntry = aStEntry2ObjDataPtrIt->first;
- // const TObjectData* data = aStEntry2ObjDataPtrIt->second;
- // if ( data->_unpublished && !data->_pyName.IsEmpty() ) {
- // aScript += createFolderCmd + data->_pyName + ")";
- // }
- // }
-
//aScript += "\n\tpass\n";
aScript += "\n";
aValidScript = true;
return id_list;
}
+void GEOM_Engine::DocumentModified(const int theDocId, const bool isModified)
+{
+ if (isModified) _mapModifiedDocs.Add(theDocId);
+ else _mapModifiedDocs.Remove(theDocId);
+}
+
+bool GEOM_Engine::DocumentModified(const int theDocId)
+{
+ return _mapModifiedDocs.Contains(theDocId);
+}
+
//===========================================================================
// Internal functions
//===========================================================================
case Aspect_TOM_POINT: aCommand += "GEOM.MT_POINT"; break;
case Aspect_TOM_PLUS: aCommand += "GEOM.MT_PLUS"; break;
case Aspect_TOM_STAR: aCommand += "GEOM.MT_STAR"; break;
- case Aspect_TOM_O: aCommand += "GEOM.MT_O"; break;
case Aspect_TOM_X: aCommand += "GEOM.MT_X"; break;
+ case Aspect_TOM_O: aCommand += "GEOM.MT_O"; break;
case Aspect_TOM_O_POINT: aCommand += "GEOM.MT_O_POINT"; break;
case Aspect_TOM_O_PLUS: aCommand += "GEOM.MT_O_PLUS"; break;
case Aspect_TOM_O_STAR: aCommand += "GEOM.MT_O_STAR"; break;
case Aspect_TOM_O_X: aCommand += "GEOM.MT_O_X"; break;
- case Aspect_TOM_BALL: aCommand += "GEOM.MT_BALL"; break;
case Aspect_TOM_RING1: aCommand += "GEOM.MT_RING1"; break;
case Aspect_TOM_RING2: aCommand += "GEOM.MT_RING2"; break;
case Aspect_TOM_RING3: aCommand += "GEOM.MT_RING3"; break;
+ case Aspect_TOM_BALL: aCommand += "GEOM.MT_BALL"; break;
default: aCommand += "GEOM.MT_NONE"; break; // just for completeness, should not get here
}
aCommand += ", ";