From 97a79670faddd69c902237007bd1c37eb202751f Mon Sep 17 00:00:00 2001 From: skv Date: Tue, 24 Mar 2015 17:09:59 +0300 Subject: [PATCH] 22869: Groups store to/Retrieve from OCAF --- src/GEOMImpl/GEOMImpl_I3DPrimOperations.cxx | 143 ++++++++++++++++++++ src/GEOMImpl/GEOMImpl_I3DPrimOperations.hxx | 22 +++ src/GEOMImpl/GEOMImpl_IPipe.hxx | 53 +++++++- src/GEOMImpl/GEOMImpl_IPipeBiNormal.hxx | 7 +- src/GEOMImpl/GEOMImpl_IPipeDiffSect.hxx | 13 +- src/GEOMImpl/GEOMImpl_IPipeShellSect.hxx | 8 +- 6 files changed, 221 insertions(+), 25 deletions(-) diff --git a/src/GEOMImpl/GEOMImpl_I3DPrimOperations.cxx b/src/GEOMImpl/GEOMImpl_I3DPrimOperations.cxx index 977dca317..db32a71e6 100644 --- a/src/GEOMImpl/GEOMImpl_I3DPrimOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_I3DPrimOperations.cxx @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,8 @@ #include #include +#include +#include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -88,6 +91,7 @@ GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, : GEOM_IOperations(theEngine, theDocID) { MESSAGE("GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations"); + myGroupOperations = new GEOMImpl_IGroupOperations(GetEngine(), GetDocID()); } //============================================================================= @@ -98,6 +102,7 @@ GEOMImpl_I3DPrimOperations::GEOMImpl_I3DPrimOperations (GEOM_Engine* theEngine, GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations() { MESSAGE("GEOMImpl_I3DPrimOperations::~GEOMImpl_I3DPrimOperations"); + delete myGroupOperations; } @@ -1475,6 +1480,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_I3DPrimOperations::MakePipe aCI.SetBase(aRefBase); aCI.SetPath(aRefPath); + aCI.SetGenerateGroups(IsGenerateGroups); //Compute the Pipe value try { @@ -1490,9 +1496,12 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_I3DPrimOperations::MakePipe return NULL; } + // Create the sequence of objects. Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; aSeq->Append(aPipe); + createGroups(aPipe, &aCI, aSeq); + //Make a Python command GEOM::TPythonDump pyDump(aFunction); @@ -1885,6 +1894,7 @@ Handle(TColStd_HSequenceOfTransient) aCI.SetPath(aRefPath); aCI.SetWithContactMode(theWithContact); aCI.SetWithCorrectionMode(theWithCorrections); + aCI.SetGenerateGroups(IsGenerateGroups); //Compute the Pipe value try { @@ -1900,9 +1910,12 @@ Handle(TColStd_HSequenceOfTransient) return NULL; } + // Create the sequence of objects. Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; aSeq->Append(aPipeDS); + createGroups(aPipeDS, &aCI, aSeq); + //Make a Python command GEOM::TPythonDump pyDump(aFunction); @@ -2059,6 +2072,7 @@ Handle(TColStd_HSequenceOfTransient) aCI.SetPath(aRefPath); aCI.SetWithContactMode(theWithContact); aCI.SetWithCorrectionMode(theWithCorrections); + aCI.SetGenerateGroups(IsGenerateGroups); //Compute the Pipe value try { @@ -2074,9 +2088,12 @@ Handle(TColStd_HSequenceOfTransient) return NULL; } + // Create the sequence of objects. Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; aSeq->Append(aPipeDS); + createGroups(aPipeDS, &aCI, aSeq); + //Make a Python command GEOM::TPythonDump pyDump(aFunction); @@ -2221,6 +2238,7 @@ Handle(TColStd_HSequenceOfTransient) aCI.SetBases(aSeqBases); aCI.SetLocations(aSeqLocs); + aCI.SetGenerateGroups(IsGenerateGroups); //Compute the Pipe value try { @@ -2236,9 +2254,12 @@ Handle(TColStd_HSequenceOfTransient) return NULL; } + // Create the sequence of objects. Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; aSeq->Append(aPipeDS); + createGroups(aPipeDS, &aCI, aSeq); + //Make a Python command GEOM::TPythonDump pyDump(aFunction); @@ -2331,6 +2352,7 @@ Handle(TColStd_HSequenceOfTransient) aCI.SetBase(aRefBase); aCI.SetPath(aRefPath); aCI.SetVector(aRefVec); + aCI.SetGenerateGroups(IsGenerateGroups); //Compute the Pipe value try { @@ -2346,9 +2368,11 @@ Handle(TColStd_HSequenceOfTransient) return NULL; } + // Create the sequence of objects. Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; aSeq->Append(aPipe); + createGroups(aPipe, &aCI, aSeq); //Make a Python command GEOM::TPythonDump pyDump(aFunction); @@ -2627,3 +2651,122 @@ Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::RestorePath SetErrorCode(OK); return aPath; } + +//============================================================================= +/*! + * createGroup + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_I3DPrimOperations::createGroup + (const Handle(GEOM_Object) &theBaseObject, + const Handle(TColStd_HArray1OfInteger) &theGroupIDs, + const TCollection_AsciiString &theName, + const TopTools_IndexedMapOfShape &theIndices) +{ + if (theBaseObject.IsNull() || theGroupIDs.IsNull()) { + return NULL; + } + + // Get the Shape type. + const Standard_Integer anID = theGroupIDs->Value(theGroupIDs->Lower()); + const Standard_Integer aNbShapes = theIndices.Extent(); + + if (anID < 1 || anID > aNbShapes) { + return NULL; + } + + const TopoDS_Shape aSubShape = theIndices.FindKey(anID); + + if (aSubShape.IsNull()) { + return NULL; + } + + // Create a group. + const TopAbs_ShapeEnum aGroupType = aSubShape.ShapeType(); + Handle(GEOM_Object) aGroup = + myGroupOperations->CreateGroup(theBaseObject, aGroupType); + + if (aGroup.IsNull() == Standard_False) { + aGroup->GetLastFunction()->SetDescription(""); + aGroup->SetName(theName.ToCString()); + + Handle(TColStd_HSequenceOfInteger) aSeqIDs = new TColStd_HSequenceOfInteger; + Standard_Integer i; + + for (i = theGroupIDs->Lower(); i <= theGroupIDs->Upper(); ++i) { + // Get and check the index. + const Standard_Integer anIndex = theGroupIDs->Value(i); + + if (anIndex < 1 || anIndex > aNbShapes) { + return NULL; + } + + // Get and check the sub-shape. + const TopoDS_Shape aSubShape = theIndices.FindKey(anIndex); + + if (aSubShape.IsNull()) { + return NULL; + } + + // Check the shape type. + if (aSubShape.ShapeType() != aGroupType) { + return NULL; + } + + aSeqIDs->Append(anIndex); + } + + myGroupOperations->UnionIDs(aGroup, aSeqIDs); + aGroup->GetLastFunction()->SetDescription(""); + } + + return aGroup; +} + +//============================================================================= +/*! + * createGroups + */ +//============================================================================= +void GEOMImpl_I3DPrimOperations::createGroups + (const Handle(GEOM_Object) &theBaseObject, + GEOMImpl_IPipe *thePipe, + Handle(TColStd_HSequenceOfTransient) &theSequence) +{ + if (theBaseObject.IsNull() || thePipe == NULL || theSequence.IsNull()) { + return; + } + + TopoDS_Shape aShape = theBaseObject->GetValue(); + + if (aShape.IsNull()) { + return; + } + + TopTools_IndexedMapOfShape anIndices; + Handle(TColStd_HArray1OfInteger) aGroupIDs; + TopoDS_Shape aShapeType; + const Standard_Integer aNbGroups = 5; + Handle(GEOM_Object) aGrps[aNbGroups]; + Standard_Integer i; + + TopExp::MapShapes(aShape, anIndices); + + // Create groups. + aGroupIDs = thePipe->GetGroupDown(); + aGrps[0] = createGroup(theBaseObject, aGroupIDs, "GROUP_DOWN", anIndices); + aGroupIDs = thePipe->GetGroupUp(); + aGrps[1] = createGroup(theBaseObject, aGroupIDs, "GROUP_UP", anIndices); + aGroupIDs = thePipe->GetGroupSide1(); + aGrps[2] = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE1", anIndices); + aGroupIDs = thePipe->GetGroupSide2(); + aGrps[3] = createGroup(theBaseObject, aGroupIDs, "GROUP_SIDE2", anIndices); + aGroupIDs = thePipe->GetGroupOther(); + aGrps[4] = createGroup(theBaseObject, aGroupIDs, "GROUP_OTHER", anIndices); + + for (i = 0; i < aNbGroups; ++i) { + if (aGrps[i].IsNull() == Standard_False) { + theSequence->Append(aGrps[i]); + } + } +} diff --git a/src/GEOMImpl/GEOMImpl_I3DPrimOperations.hxx b/src/GEOMImpl/GEOMImpl_I3DPrimOperations.hxx index 43ff36251..51c01fe43 100644 --- a/src/GEOMImpl/GEOMImpl_I3DPrimOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_I3DPrimOperations.hxx @@ -30,6 +30,11 @@ #include #include +class GEOMImpl_IGroupOperations; +class GEOMImpl_IPipe; +class TopTools_IndexedMapOfShape; + + class GEOMImpl_I3DPrimOperations : public GEOM_IOperations { public: Standard_EXPORT GEOMImpl_I3DPrimOperations(GEOM_Engine* theEngine, int theDocID); @@ -165,6 +170,23 @@ class GEOMImpl_I3DPrimOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) RestorePath (Handle(GEOM_Object) theShape, const Handle(TColStd_HSequenceOfTransient)& theBase1, const Handle(TColStd_HSequenceOfTransient)& theBase2); + +private: + + Handle(GEOM_Object) createGroup + (const Handle(GEOM_Object) &theBaseObject, + const Handle(TColStd_HArray1OfInteger) &theGroupIDs, + const TCollection_AsciiString &theName, + const TopTools_IndexedMapOfShape &theIndices); + + void createGroups(const Handle(GEOM_Object) &theBaseObject, + GEOMImpl_IPipe *thePipe, + Handle(TColStd_HSequenceOfTransient) &theSequence); + +private: + + GEOMImpl_IGroupOperations *myGroupOperations; + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_IPipe.hxx b/src/GEOMImpl/GEOMImpl_IPipe.hxx index 22ace08b3..fc346c5f1 100644 --- a/src/GEOMImpl/GEOMImpl_IPipe.hxx +++ b/src/GEOMImpl/GEOMImpl_IPipe.hxx @@ -27,20 +27,69 @@ #include "GEOM_Function.hxx" -#define PIPE_ARG_BASE 1 -#define PIPE_ARG_PATH 2 +#include + +// ---- GEOMImpl_IPipe +#define PIPE_ARG_BASE 1 +#define PIPE_ARG_PATH 2 + +// ---- GEOMImpl_IPipeBiNormal +#define PIPE_ARG_VEC 3 + +// ---- GEOMImpl_IPipeDiffSect +#define PIPEDS_LIST_BASES 1 +//#define PIPEDS_ARG_PATH 2 +#define PIPEDS_LIST_LOCATIONS 3 +#define PIPEDS_ARG_WITHCONTACT 4 +#define PIPEDS_ARG_WITHCORRECT 5 + +// ---- GEOMImpl_IPipeShellSect +#define PIPEDS_LIST_SUBBASES 6 + +// ---- Generate groups block (common) +#define PIPE_GENERATE_GROUPS 7 +#define PIPE_GROUP_DOWN 8 +#define PIPE_GROUP_UP 9 +#define PIPE_GROUP_SIDE1 10 +#define PIPE_GROUP_SIDE2 11 +#define PIPE_GROUP_OTHER 12 + class GEOMImpl_IPipe { public: GEOMImpl_IPipe(Handle(GEOM_Function) theFunction): _func(theFunction) {} + virtual ~GEOMImpl_IPipe() {} void SetBase (Handle(GEOM_Function) theBase) { _func->SetReference(PIPE_ARG_BASE, theBase); } void SetPath (Handle(GEOM_Function) thePath) { _func->SetReference(PIPE_ARG_PATH, thePath); } + void SetGenerateGroups (int theGenerateGroups) + { _func->SetInteger(PIPE_GENERATE_GROUPS, theGenerateGroups); } + void SetGroupDown (const Handle(TColStd_HArray1OfInteger) &theGroup) + { _func->SetIntegerArray(PIPE_GROUP_DOWN, theGroup); } + void SetGroupUp (const Handle(TColStd_HArray1OfInteger) &theGroup) + { _func->SetIntegerArray(PIPE_GROUP_UP, theGroup); } + void SetGroupSide1 (const Handle(TColStd_HArray1OfInteger) &theGroup) + { _func->SetIntegerArray(PIPE_GROUP_SIDE1, theGroup); } + void SetGroupSide2 (const Handle(TColStd_HArray1OfInteger) &theGroup) + { _func->SetIntegerArray(PIPE_GROUP_SIDE2, theGroup); } + void SetGroupOther (const Handle(TColStd_HArray1OfInteger) &theGroup) + { _func->SetIntegerArray(PIPE_GROUP_OTHER, theGroup); } Handle(GEOM_Function) GetBase() { return _func->GetReference(PIPE_ARG_BASE); } Handle(GEOM_Function) GetPath() { return _func->GetReference(PIPE_ARG_PATH); } + int GetGenerateGroups () { return _func->GetInteger(PIPE_GENERATE_GROUPS); } + Handle(TColStd_HArray1OfInteger) GetGroupDown () + { return _func->GetIntegerArray(PIPE_GROUP_DOWN); } + Handle(TColStd_HArray1OfInteger) GetGroupUp () + { return _func->GetIntegerArray(PIPE_GROUP_UP); } + Handle(TColStd_HArray1OfInteger) GetGroupSide1 () + { return _func->GetIntegerArray(PIPE_GROUP_SIDE1); } + Handle(TColStd_HArray1OfInteger) GetGroupSide2 () + { return _func->GetIntegerArray(PIPE_GROUP_SIDE2); } + Handle(TColStd_HArray1OfInteger) GetGroupOther () + { return _func->GetIntegerArray(PIPE_GROUP_OTHER); } protected: diff --git a/src/GEOMImpl/GEOMImpl_IPipeBiNormal.hxx b/src/GEOMImpl/GEOMImpl_IPipeBiNormal.hxx index 8d3780f1a..e6b154c16 100644 --- a/src/GEOMImpl/GEOMImpl_IPipeBiNormal.hxx +++ b/src/GEOMImpl/GEOMImpl_IPipeBiNormal.hxx @@ -22,15 +22,10 @@ #ifndef _GEOMImpl_IPIPEBINORMAL_HXX_ #define _GEOMImpl_IPIPEBINORMAL_HXX_ -#include "GEOM_Function.hxx" -#ifndef _GEOMImpl_IPIPE_HXX_ #include "GEOMImpl_IPipe.hxx" -#endif -#define PIPE_ARG_BASE 1 -#define PIPE_ARG_PATH 2 -#define PIPE_ARG_VEC 3 +// Position definitions are declared in the base class. class GEOMImpl_IPipeBiNormal : public GEOMImpl_IPipe { diff --git a/src/GEOMImpl/GEOMImpl_IPipeDiffSect.hxx b/src/GEOMImpl/GEOMImpl_IPipeDiffSect.hxx index 563d32633..902f0cf4d 100644 --- a/src/GEOMImpl/GEOMImpl_IPipeDiffSect.hxx +++ b/src/GEOMImpl/GEOMImpl_IPipeDiffSect.hxx @@ -25,20 +25,11 @@ #ifndef _GEOMImpl_IPIPEDIFFSECT_HXX_ #define _GEOMImpl_IPIPEDIFFSECT_HXX_ -#include "GEOM_Function.hxx" -#include - -#ifndef _GEOMImpl_IPIPE_HXX_ #include "GEOMImpl_IPipe.hxx" -#endif - -#define PIPEDS_LIST_BASES 1 -#define PIPEDS_LIST_LOCATIONS 3 -//#define PIPEDS_ARG_PATH 2 -#define PIPEDS_ARG_WITHCONTACT 4 -#define PIPEDS_ARG_WITHCORRECT 5 +#include +// Position definitions are declared in the base class. class GEOMImpl_IPipeDiffSect : public GEOMImpl_IPipe { diff --git a/src/GEOMImpl/GEOMImpl_IPipeShellSect.hxx b/src/GEOMImpl/GEOMImpl_IPipeShellSect.hxx index e65a60b1f..f162a0b97 100644 --- a/src/GEOMImpl/GEOMImpl_IPipeShellSect.hxx +++ b/src/GEOMImpl/GEOMImpl_IPipeShellSect.hxx @@ -22,16 +22,12 @@ #ifndef _GEOMImpl_IPIPESHELLSECT_HXX_ #define _GEOMImpl_IPIPESHELLSECT_HXX_ -#include "GEOM_Function.hxx" -#ifndef _GEOMImpl_IPIPEDIFFSECT_HXX_ #include "GEOMImpl_IPipeDiffSect.hxx" -#endif - +#include "GEOM_Function.hxx" #include -#define PIPEDS_LIST_SUBBASES 6 - +// Position definitions are declared in the base class GEOMImpl_IPipe. class GEOMImpl_IPipeShellSect : public GEOMImpl_IPipeDiffSect { -- 2.39.2