X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM%2FGEOM_Engine.cxx;h=dd7fefae6afb03f4a8dbfb025a7ca14d3af57f7a;hb=d617faae6bc5aeb91b63796618a20c7c13037b6c;hp=1293fd8ed24f81f6adf1059cf83ccb8b3f76a038;hpb=5e7cf6df5a668d1e1608ba946c59ba34234d8942;p=modules%2Fgeom.git diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 1293fd8ed..dd7fefae6 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -34,11 +34,10 @@ #include "GEOM_SubShapeDriver.hxx" #include "Sketcher_Profile.hxx" -#include - #include "utilities.h" #include +#include #include #include @@ -64,13 +63,13 @@ #include +#if OCC_VERSION_LARGE < 0x07050000 #include +#endif -#if OCC_VERSION_LARGE > 0x07000000 #include #include #include -#endif #include @@ -84,11 +83,13 @@ #define C_SQR_BRACKET ']' #define PY_NULL "None" -#ifdef _DEBUG_ -static int MYDEBUG = 0; -#else -static int MYDEBUG = 0; -#endif +// VSR 29/08/2017: 0023327, 0023428: eliminate unnecessary lines in Python dump +// Next macro, when defined, causes appearing of SubShapeAllIDs(), SubShapeAllSortedIDs(), GetSameIDs() +// and other such commands in Python dump. +// See also GEOMImpl_IShapesOperations.cxx. +// --------------------------------------- +// #define DUMP_SUBSHAPE_IDS +// --------------------------------------- typedef std::map< TCollection_AsciiString, TCollection_AsciiString > TSting2StringMap; typedef std::map< TCollection_AsciiString, TObjectData > TSting2ObjDataMap; @@ -109,7 +110,7 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction, TCollection_AsciiString& theScript, TCollection_AsciiString& theAfterScript, const TVariablesList& theVariables, - const bool theIsPublished, + const bool /*theIsPublished*/, TDF_LabelMap& theProcessed, std::set& theIgnoreObjs, bool& theIsDumpCollected); @@ -149,6 +150,8 @@ static TCollection_AsciiString GetPublishCommands const TIntToListIntMap &theMapRefs, std::set< int > &thePublished); +void Prettify(TCollection_AsciiString& theScript); + //================================================================================ /*! * \brief Fix up the name of python variable @@ -215,11 +218,9 @@ GEOM_Engine::GEOM_Engine() TFunction_DriverTable::Get()->AddDriver(GEOM_Object::GetSubShapeID(), new GEOM_SubShapeDriver()); _OCAFApp = new GEOM_Application(); -#if OCC_VERSION_LARGE > 0x07000000 _OCAFApp->DefineFormat("SALOME_GEOM", "GEOM Document Version 1.0", "sgd", new StdDrivers_DocumentRetrievalDriver, 0); BinDrivers::DefineFormat(_OCAFApp); -#endif _UndoLimit = 0; } @@ -253,11 +254,7 @@ Handle(TDocStd_Document) GEOM_Engine::GetDocument(bool force) aDoc = _document; } else if (force) { -#if OCC_VERSION_MAJOR > 6 _OCAFApp->NewDocument("BinOcaf", aDoc); -#else - _OCAFApp->NewDocument("SALOME_GEOM", aDoc); -#endif aDoc->SetUndoLimit(_UndoLimit); _document = aDoc; } @@ -393,9 +390,8 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) th return NULL; } } - catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); - MESSAGE("GEOM_Engine::AddSubShape Error: " << aFail->GetMessageString()); + catch (Standard_Failure& aFail) { + MESSAGE("GEOM_Engine::AddSubShape Error: " << aFail.GetMessageString()); return NULL; } @@ -435,6 +431,10 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject) if(!_document) return false; // document is closed... + TDF_Label aLabel = theObject->GetEntry(); + if ( aLabel == aLabel.Root() ) + return false; // already removed object + //Remove an object from the map of available objects TCollection_AsciiString anID = BuildIDFromObject(theObject); if (_objects.IsBound(anID)) { @@ -463,14 +463,13 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject) aNode->Remove(); } - TDF_Label aLabel = theObject->GetEntry(); aLabel.ForgetAllAttributes(Standard_True); // Remember the label to reuse it then if ( _freeLabels.empty() || _freeLabels.back() != aLabel ) _freeLabels.push_back(aLabel); - // we can't explicitely delete theObject. At least prevent its functioning + // we can't explicitly 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(); @@ -510,9 +509,13 @@ bool GEOM_Engine::Save(const char* theFileName) { if(!_document) return false; - _OCAFApp->SaveAs(_document, theFileName); +#if defined(WIN32) && defined(UNICODE) + std::wstring aFileName = Kernel_Utils::utf8_decode_s(theFileName); +#else + std::string aFileName = theFileName; +#endif - return true; + return _OCAFApp->SaveAs( _document, aFileName.c_str() ) == PCDM_SS_OK; } //============================================================================= @@ -522,17 +525,20 @@ bool GEOM_Engine::Save(const char* theFileName) //============================================================================= bool GEOM_Engine::Load(const char* theFileName) { +#if defined(WIN32) && defined(UNICODE) + std::wstring aFileName = Kernel_Utils::utf8_decode_s(theFileName); +#else + std::string aFileName = theFileName; +#endif Handle(TDocStd_Document) aDoc; - if (_OCAFApp->Open(theFileName, aDoc) != PCDM_RS_OK) { + if (_OCAFApp->Open(aFileName.c_str(), aDoc) != PCDM_RS_OK) { return false; } -#if OCC_VERSION_MAJOR > 6 // Replace old document format by the new one. if (aDoc->StorageFormat().IsEqual("SALOME_GEOM")) { aDoc->ChangeStorageFormat("BinOcaf"); } -#endif aDoc->SetUndoLimit(_UndoLimit); @@ -611,7 +617,7 @@ TCollection_AsciiString GEOM_Engine::DumpPython(std::vector& theObj // a map containing copies of TObjectData from theObjectData TSting2ObjDataMap aEntry2ObjData; // contains pointers to TObjectData of either aEntry2ObjData or theObjectData; the latter - // occures when several StudyEntries correspond to one Entry + // occurs when several StudyEntries correspond to one Entry TSting2ObjDataPtrMap aStEntry2ObjDataPtr; //Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry, theObjectNames; @@ -811,6 +817,11 @@ TCollection_AsciiString GEOM_Engine::DumpPython(std::vector& theObj aScript.Insert( posToInsertGlobalVars, globalVars ); } + // VSR 29/08/2017: 0023327, 0023428: eliminate unnecessary lines in Python dump +#ifndef DUMP_SUBSHAPE_IDS + Prettify(aScript); +#endif + return aScript; } @@ -1263,7 +1274,7 @@ Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theStrin if(c == 58) isFound = Standard_True; } - if(isFound && arr[j-2] != 58) { // last char should be a diggit + if(isFound && arr[j-2] != 58) { // last char should be a digit aSeq->Append(i+1); // +1 because AsciiString starts from 1 aSeq->Append(j-1); } @@ -1284,14 +1295,14 @@ Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theStrin void ReplaceVariables(TCollection_AsciiString& theCommand, const TVariablesList& theVariables) { - if (MYDEBUG) - cout<<"Command : "<GetCurrectState(); - if(MYDEBUG) { - cout<<"Variables from SObject:"<= aVariables.size()) continue; @@ -1475,28 +1488,31 @@ void ReplaceVariables(TCollection_AsciiString& theCommand, aReplacedParameter.InsertAfter(aReplacedParameter.Length(),"'"); } - if(MYDEBUG) - cout<<"aSection before : "<IncrementState(); } - if (MYDEBUG) - cout<<"Command : "<healPyName( data._pyName, anEntry, aNameToEntry); @@ -1780,7 +1796,7 @@ void PublishObject (TObjectData& theObjectData, // store aCreationCommand before publishing commands int tag = GetTag(theObjectData._entry); - theEntryToCmdMap.insert( std::make_pair( tag + 2*theEntry2ObjData.size(), aCreationCommand )); + theEntryToCmdMap.insert( std::make_pair( tag + -2*theEntry2ObjData.size(), aCreationCommand )); } // make a command @@ -1816,6 +1832,8 @@ TCollection_AsciiString GetPublishCommands if (!thePublished.count(theTag)) { // This object is not published yet. + thePublished.insert(theTag); + std::map< int, TCollection_AsciiString >::const_iterator anIt = theEntryToCmdMap.find(theTag); @@ -1824,7 +1842,7 @@ TCollection_AsciiString GetPublishCommands TIntToListIntMap::const_iterator aRefIt = theMapRefs.find(theTag); if (aRefIt != theMapRefs.end()) { - // Recursively publish all references. + // Recursively publish all references. std::list< int >::const_iterator aRefTagIt = aRefIt->second.begin(); for(; aRefTagIt != aRefIt->second.end(); ++aRefTagIt) { @@ -1838,13 +1856,48 @@ TCollection_AsciiString GetPublishCommands // Add the object command. aResult += anIt->second; } - - thePublished.insert(theTag); } return aResult; } +void Prettify(TCollection_AsciiString& theScript) +{ + TCollection_AsciiString output; + static std::list ToRemove; + if (ToRemove.empty()) { + ToRemove.push_back("geompy.SubShapeAllIDs"); + ToRemove.push_back("geompy.SubShapeAllSortedCentresIDs"); + ToRemove.push_back("geompy.SubShapeAllSortedIDs"); + ToRemove.push_back("geompy.GetFreeFacesIDs"); + ToRemove.push_back("geompy.GetShapesOnBoxIDs"); + ToRemove.push_back("geompy.GetShapesOnShapeIDs"); + ToRemove.push_back("geompy.GetShapesOnPlaneIDs"); + ToRemove.push_back("geompy.GetShapesOnPlaneWithLocationIDs"); + ToRemove.push_back("geompy.GetShapesOnCylinderIDs"); + ToRemove.push_back("geompy.GetShapesOnCylinderWithLocationIDs"); + ToRemove.push_back("geompy.GetShapesOnSphereIDs"); + ToRemove.push_back("geompy.GetShapesOnQuadrangleIDs"); + ToRemove.push_back("geompy.GetSameIDs"); + } + + int start = 1; + while (start <= theScript.Length()) { + int end = theScript.Location("\n", start, theScript.Length()); + if (end == -1) end = theScript.Length(); + TCollection_AsciiString line = theScript.SubString(start, end); + bool found = false; + for (std::list::const_iterator it = ToRemove.begin(); it != ToRemove.end() && !found; ++it) + found = line.Search( *it ) != -1; + if (!found) + output += line; + start = end + 1; + } + theScript = output; + + //OK @@@@@@@@@@@@@@@@@@@@@@@@@@@ +} + //================================================================================ /*! * \brief Constructor @@ -1872,7 +1925,7 @@ ObjectStates::~ObjectStates() //================================================================================ TState ObjectStates::GetCurrectState() const { - if(_states.size() > _dumpstate) + if((int)_states.size() > _dumpstate) return _states[_dumpstate]; return TState(); }