X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStudyData%2FStudyData_Object.cpp;h=ae88a1e179f7e4d962c44ba955de1c7350b53474;hb=6a1ca8d833e9b3d06da192cc3e14704885a99098;hp=13e22ddcb389213986aabb675ac4e02289528c81;hpb=0753cb5ab5f31f03ec671975de920a81653f637b;p=modules%2Fshaper_study.git diff --git a/src/StudyData/StudyData_Object.cpp b/src/StudyData/StudyData_Object.cpp index 13e22dd..ae88a1e 100644 --- a/src/StudyData/StudyData_Object.cpp +++ b/src/StudyData/StudyData_Object.cpp @@ -1,7 +1,4 @@ -// Copyright (C) 2007-2019 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 +// Copyright (C) 2019-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -22,12 +19,157 @@ #include "StudyData_Object.h" +#include +#include #include #include +#include StudyData_Object::StudyData_Object(const std::string theFile) { std::istringstream streamBrep(theFile.c_str()); BRep_Builder aBuilder; BRepTools::Read(myShape, streamBrep, aBuilder); + myTick = 1; + myStream = theFile; +} + +StudyData_Object::StudyData_Object() +{ + myTick = 0; // when shape is defined, it will be increased to 1 +} + +int StudyData_Object::type() const +{ + if (myShape.IsNull()) + return 8; // GEOM.SHAPE + return (int) myShape.ShapeType(); +} + +std::string StudyData_Object::shapeStream() const +{ + return myStream; +} + +std::string StudyData_Object::oldShapeStream() const +{ + return myOldStream.empty() ? myStream : myOldStream; +} + +long long StudyData_Object::shape() const +{ + return ((long long)(&myShape)); +} + +void StudyData_Object::updateShape(const std::string theFile) +{ + if (myStream == theFile) { // absolutely identical shapes, no need to store + return; + } + long aDelta = (long)myStream.size() - (long)theFile.size(); + aDelta = aDelta < 0 ? -aDelta : aDelta; + long aSum = (long)myStream.size() + (long)theFile.size(); + if (double(aDelta) / aSum < 0.05) { // size-difference is less than 10% + // check numbers have the minimal differnce + std::istringstream aMyStr(myStream); + std::istringstream aFileStr(theFile); + double aMyNum, aFileNum; + std::string aBuf1, aBuf2; + while(aMyStr && aFileStr) { + if (aMyStr>>aMyNum) { + if (aFileStr>>aFileNum) { + if (std::abs(aMyNum - aFileNum) > 1.e-9) + break; // different numbers + } else { + break; // number and not number + } + } else if (aFileStr>>aFileNum) { + break; // number and not number + } else { // read two non-numbers + aMyStr.clear(); + aMyStr>>aBuf1; + aFileStr.clear(); + aFileStr>>aBuf2; + if (aBuf1 != aBuf2) + break; // strings are different + } + } + if (!aMyStr || !aFileStr) // both get to the end with equal content + return; + } + + // update the current shape + std::istringstream streamBrep(theFile.c_str()); + BRep_Builder aBuilder; + myOldShape = myShape; + BRepTools::Read(myShape, streamBrep, aBuilder); + myTick++; + myOldStream = myStream; + myStream = theFile; +} + +int StudyData_Object::getTick() const +{ + return myTick; +} + +void StudyData_Object::setTick(const int theValue) +{ + myTick = theValue; +} + +void StudyData_Object::SetShapeByPointer(const long long theShape) +{ + myOldShape = myShape; + myShape = *((TopoDS_Shape*)theShape); + std::ostringstream aStreamBrep; + if (!myShape.IsNull()) { + BRepTools::Write(myShape, aStreamBrep); + } + myOldStream = myStream; + myStream = aStreamBrep.str(); + myTick++; +} + +long long StudyData_Object::groupShape(long long theMainShape, const std::list theSelection) +{ + if (myShape.IsNull()) { // compute the cashed shape + TopoDS_Shape* aShape = (TopoDS_Shape*)theMainShape; + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(*aShape, anIndices); + + TopoDS_Compound aResult; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aResult); + + std::list::const_iterator aSelIter = theSelection.cbegin(); + for(; aSelIter != theSelection.cend(); aSelIter++) { + TopoDS_Shape aSel = anIndices.FindKey(*aSelIter); + aBuilder.Add(aResult, aSel); + } + myShape = aResult; + } else { // check myShape equals to the new result + TopoDS_Shape* aShape = (TopoDS_Shape*)theMainShape; + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(*aShape, anIndices); + TopoDS_Iterator aMyIter(myShape); + std::list::const_iterator aSelIter = theSelection.cbegin(); + for(; aSelIter != theSelection.cend() && aMyIter.More(); aSelIter++, aMyIter.Next()) { + TopoDS_Shape aSel = anIndices.FindKey(*aSelIter); + if (!aSel.IsSame(aMyIter.Value())) + break; + } + if (aMyIter.More() || aSelIter != theSelection.cend()) { // recompute myShape + TopoDS_Compound aResult; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aResult); + std::list::const_iterator aSelIter = theSelection.cbegin(); + for(; aSelIter != theSelection.cend(); aSelIter++) { + TopoDS_Shape aSel = anIndices.FindKey(*aSelIter); + aBuilder.Add(aResult, aSel); + } + myShape = aResult; + } + } + return (long long)(&myShape); }