From 5d596454037e662a3f2706be9c716118ec96bc3a Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 5 Sep 2018 14:21:30 +0300 Subject: [PATCH 1/5] 23586: [EDF] HYDRO: Copy mesh to new geometry --- GEOM_Gen_i.cc --- In order to assure safe and fast search of initial groups by groups of the new geometry, behavior of GEOM_Gen operations that implement searching and publishing of new groups corresponding to initial groups, is slightly modified. A reference to an initial sub-object is published under a corresponding new sub-object. The modified functions are RestoreSubShapesO(), RestoreGivenSubShapesO() and RestoreSubShapesSO(). --- GEOM_Engine.cxx --- Avoid double removal of GEOM_BaseObject that leads to removal of all attributes from the root TDF label. That caused some regression, don't remember which. --- src/GEOM/GEOM_Engine.cxx | 11 +++++++---- src/GEOM_I/GEOM_Gen_i.cc | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index dd4bc1012..e0fb46fe2 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -482,6 +482,10 @@ bool GEOM_Engine::RemoveObject(Handle(GEOM_BaseObject)& theObject) if(!_mapIDDocument.IsBound(aDocID)) 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)) { @@ -510,7 +514,6 @@ 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 @@ -1432,7 +1435,7 @@ void ReplaceVariables(TCollection_AsciiString& theCommand, if(MYDEBUG) { cout<<"Variables from SObject:"< #include +#include class GEOM_Engine; class GEOM_Object; @@ -329,6 +330,10 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations Standard_EXPORT Handle(GEOM_Object) GetInPlaceByHistory (Handle(GEOM_Object) theShapeWhere, Handle(GEOM_Object) theShapeWhat); + Standard_EXPORT void GetInPlaceMap (Handle(GEOM_Object) theShapeWhere, + Handle(GEOM_Object) theShapeWhat, + std::vector< std::vector< int > > & theResVec); + /*! * \brief Searches a shape equal to theWhat in the context of theWhere * \param theShapeWhere - a context shap diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index 6aa10a803..c9f451328 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -35,6 +35,8 @@ #include #include +#include + /** * This function converts GEOM::comparison_condition type into * GEOMUtils::ComparisonCondition type. @@ -1985,6 +1987,39 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetInPlaceByHistory return GetObject(anObject); } +//============================================================================= +/*! + * GetInPlaceMap + */ +//============================================================================= +GEOM::ListOfListOfLong* +GEOM_IShapesOperations_i::GetInPlaceMap (GEOM::GEOM_Object_ptr theShapeWhere, + GEOM::GEOM_Object_ptr theShapeWhat) +{ + GEOM::ListOfListOfLong_var aResult = new GEOM::ListOfListOfLong(); + + //Get the reference objects + Handle(::GEOM_Object) aShapeWhere = GetObjectImpl(theShapeWhere); + Handle(::GEOM_Object) aShapeWhat = GetObjectImpl(theShapeWhat); + + if (!aShapeWhere.IsNull() && + !aShapeWhat.IsNull()) + { + std::vector< std::vector< int > > resVec; + GetOperations()->GetInPlaceMap(aShapeWhere, aShapeWhat, resVec); + + aResult->length( resVec.size() ); + for ( size_t i = 0; i < resVec.size(); ++i ) + { + //if ( !resVec[i].empty() ) + aResult[i].length( resVec[i].size() ); + for ( size_t j = 0; j < resVec[i].size(); ++j ) + aResult[i][j] = resVec[i][j]; + } + } + return aResult._retn(); +} + //============================================================================= /*! * GetSame diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index c48e6b7e1..f9e457629 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -279,6 +279,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i : GEOM::GEOM_Object_ptr GetInPlaceByHistory (GEOM::GEOM_Object_ptr theShapeWhere, GEOM::GEOM_Object_ptr theShapeWhat); + GEOM::ListOfListOfLong* GetInPlaceMap(GEOM::GEOM_Object_ptr theShapeWhere, + GEOM::GEOM_Object_ptr theShapeWhat); + GEOM::GEOM_Object_ptr GetSame (GEOM::GEOM_Object_ptr theShapeWhere, GEOM::GEOM_Object_ptr theShapeWhat); diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index e3b56a228..b28117581 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -5960,6 +5960,38 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): self._autoPublish(anObj, theName, "inplace") return anObj + ## A sort of GetInPlace functionality, returning IDs of sub-shapes. + # For each sub-shape ID of @a theShapeWhat return a list of corresponding sub-shape + # IDs of @a theShapeWhere. + # For example, if theShapeWhat is a box and theShapeWhere is this box cut into + # two parts by a plane, then the result can be as this: + # len( result_list ) = 35, + # result_list[ 1 ] = [ 2, 36 ], which means that the box (ID 1) turned into two + # solids with IDs 2 and 36 within theShapeWhere + # + # @param theShapeWhere Shape to find sub-shapes of. + # @param theShapeWhat Shape, specifying what to find. + # @return List of lists of sub-shape IDS of theShapeWhere. + def GetInPlaceMap(self, theShapeWhere, theShapeWhat): + """ + A sort of GetInPlace functionality, returning IDs of sub-shapes. + For each sub-shape ID of @a theShapeWhat return a list of corresponding sub-shape + IDs of @a theShapeWhere. + For example, if theShapeWhat is a box and theShapeWhere is this box cut into + two parts by a plane, then the result can be as this: + len( result_list ) = 35, + result_list[ 1 ] = [ 2, 36 ], which means that the box (ID 1) turned into two + solids with IDs 2 and 36 within theShapeWhere + + Parameters: + theShapeWhere Shape to find sub-shapes of. + theShapeWhat Shape, specifying what to find. + + Returns: + List of lists of sub-shape IDS of theShapeWhere. + """ + return self.ShapesOp.GetInPlaceMap(theShapeWhere, theShapeWhat) + ## Get sub-shape of theShapeWhere, which is # equal to \a theShapeWhat. # @param theShapeWhere Shape to find sub-shape of. From aed513ce80ebae678fb026941dfde0615c535635 Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 25 Sep 2018 13:24:25 +0300 Subject: [PATCH 3/5] Hydro lots 3/8 --- resources/CMakeLists.txt | 1 + resources/setcolor.png | Bin 0 -> 580 bytes src/CurveCreator/CurveCreator_Curve.cxx | 82 +++++++++++++++++--- src/CurveCreator/CurveCreator_Curve.hxx | 26 ++++++- src/CurveCreator/CurveCreator_Diff.cxx | 32 ++++++++ src/CurveCreator/CurveCreator_Diff.hxx | 14 ++++ src/CurveCreator/CurveCreator_Operation.cxx | 36 ++++++++- src/CurveCreator/CurveCreator_Operation.hxx | 12 ++- src/CurveCreator/CurveCreator_Section.hxx | 4 +- src/CurveCreator/CurveCreator_TreeView.cxx | 21 +++-- src/CurveCreator/CurveCreator_TreeView.h | 5 +- src/CurveCreator/CurveCreator_Utils.cxx | 37 ++++++++- src/CurveCreator/CurveCreator_Utils.hxx | 20 ++++- src/CurveCreator/CurveCreator_Widget.cxx | 44 ++++++++++- src/CurveCreator/CurveCreator_Widget.h | 7 +- src/GEOMGUI/GEOM_images.ts | 4 + src/GEOMGUI/GEOM_msg_en.ts | 8 ++ 17 files changed, 323 insertions(+), 30 deletions(-) create mode 100644 resources/setcolor.png diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 74be117a6..ff1e39d94 100755 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -270,6 +270,7 @@ SET( _res_files propagate.png redo.png undo.png + setcolor.png glue2.png remove_webs.png remove_extra_edges.png diff --git a/resources/setcolor.png b/resources/setcolor.png new file mode 100644 index 0000000000000000000000000000000000000000..15b95453c7c3f75a861383729232c7b4769e3950 GIT binary patch literal 580 zcmV-K0=xZ*P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E-^MlX|MGF00Fc~L_t(IPsLO_NCQC-eeqi;Vxa`YB)6B4 z!bVZhLP1EYm0)FIVLEgX|;Gi-5bswG@Hu z(p%;r$(RMVY$H3t3{R=2^_DppJV&xu3)x;9QV|vgu-~Y+gM$~}#L~7&a25y`0VeB7 zc1MDDmOai9Nl|`_!bxd|zzErJhj~vP3G!+zxbkVa#VSTb)-m{incXrt$I;-^^3G_x zi9*`iDL8alSBhBa0xN@T$m8$q8H3pzl5m}(-$4sbta5-MVpy_x@te%%n`Pcd;KVBf z?dE9P&~CxOz(r>FsR%2i-WQwj!Sx}Dbcc2`gZiH_%T2EE8OsC%dF91IZOL`{& Smobt60000 #include #include - +#include #include #include #define DEBTRACE(msg) {std::cerr<myType = theType; aSection->myIsClosed = theIsClosed; aSection->myPoints = thePoints; + aSection->myColor = aColor;//getRandColor(); //TODO temp mySections.push_back(aSection); redisplayCurve(false); return mySections.size()-1; @@ -514,7 +516,9 @@ int CurveCreator_Curve::addSection theName, aCoords, theType, theIsClosed); } - resISection = addSectionInternal(theName, theType, theIsClosed, aCoords); + Quantity_Color aRColor = CurveCreator_Utils::getRandColor(); + + resISection = addSectionInternal(theName, theType, theIsClosed, aCoords, aRColor); finishOperation(); return resISection; @@ -535,7 +539,7 @@ int CurveCreator_Curve::addSection theName, thePoints, theType, theIsClosed); } - resISection = addSectionInternal(theName, theType, theIsClosed, thePoints); + resISection = addSectionInternal(theName, theType, theIsClosed, thePoints, Quantity_NOC_YELLOW); finishOperation(); return resISection; @@ -544,12 +548,16 @@ int CurveCreator_Curve::addSection //! For internal use only! Undo/Redo are not used here. bool CurveCreator_Curve::removeSectionInternal( const int theISection ) { - if (theISection == -1) { + if (theISection == -1) + { + myRemColors.push_back(mySections.back()->myColor); delete mySections.back(); mySections.pop_back(); } else { CurveCreator::Sections::iterator anIterRm = mySections.begin() + theISection; + myRemColors.push_back((*anIterRm)->myColor); + delete *anIterRm; mySections.erase(anIterRm); } @@ -572,6 +580,49 @@ bool CurveCreator_Curve::removeSection( const int theISection ) return res; } +bool CurveCreator_Curve::setColorSection( int SectInd, Quantity_Color theNewColor ) +{ + bool res = false; + // Set the difference. + startOperation(); + + int ColorParam[3] = { (int)( theNewColor.Red() * 255 ), + (int)( theNewColor.Green() * 255 ), + (int)( theNewColor.Blue() * 255 ) }; + + if (addEmptyDiff()) + myListDiffs.back().init(this, CurveCreator_Operation::SetColorSection, SectInd, ColorParam); + + setColorSectionInternal(SectInd, theNewColor); + + finishOperation(); + return res; +} + +void CurveCreator_Curve::setColorSectionInternal( int SectInd, Quantity_Color theNewColor ) +{ + CurveCreator_Section* aSec = (CurveCreator_Section*)(getSection(SectInd)); + aSec->myColor = theNewColor; + + redisplayCurve(false); +} + +Quantity_Color CurveCreator_Curve::getColorSection( int SectInd ) const +{ + CurveCreator_Section* aSec = (CurveCreator_Section*)(getSection(SectInd)); + return aSec->myColor; +} + +Quantity_Color CurveCreator_Curve::getLastRemovedColor() const +{ + return myRemColors.empty() ? Quantity_NOC_BLACK : myRemColors.back(); +} + +void CurveCreator_Curve::popLastRemovedColor() +{ + myRemColors.pop_back(); +} + /** * Get number of points in specified section or (the total number of points * in Curve if theISection is equal to -1). @@ -1016,9 +1067,22 @@ void CurveCreator_Curve::constructAISObject() { //DEBTRACE("constructAISObject"); TopoDS_Shape aShape; - CurveCreator_Utils::constructShape( this, aShape ); - myAISShape = new AIS_Shape( aShape ); - myAISShape->SetColor( myCurveColor ); + std::map Sect2Wire; + CurveCreator_Utils::constructShape( this, aShape, &Sect2Wire ); + myAISShape = new AIS_ColoredShape( aShape ); + AIS_ColoredShape* AISColoredShape = dynamic_cast(myAISShape); + + std::map::iterator it; + + for ( it = Sect2Wire.begin(); it != Sect2Wire.end(); it++ ) + { + CurveCreator_Section* aSect = it->first; + Quantity_Color aColor = aSect->myColor; + const TopoDS_Shape& aWire = it->second; + AISColoredShape->SetCustomColor(aWire, aColor); + } + + // myAISShape->SetColor( myCurveColor ); myAISShape->SetWidth( myLineWidth ); Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect(); anAspect->SetScale( 3.0 ); diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx index 08239f4e7..e73a00883 100644 --- a/src/CurveCreator/CurveCreator_Curve.hxx +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -108,7 +108,7 @@ protected: public: // TODO: remove public void getCoordinates( int theISection, int theIPoint, double& theX, double& theY, double& theZ ) const; -protected: // TODO: remove public +protected: //TODO void redisplayCurve(bool preEraseAllObjects = true); public: @@ -162,7 +162,8 @@ public: virtual int addSectionInternal( const std::string &theName, const CurveCreator::SectionType theType, const bool theIsClosed, - const CurveCreator::Coordinates &thePoints); + const CurveCreator::Coordinates &thePoints, + const Quantity_Color& aColor); //! Add a new section. virtual int addSection( const std::string &theName, const CurveCreator::SectionType theType, @@ -191,6 +192,19 @@ public: virtual bool setClosed( const int theISection, const bool theIsClosed ); + //! Sets color of section by index + virtual bool setColorSection( int SectInd, Quantity_Color theNewColor ); + + //! For internal use only! Undo/Redo are not used here. + virtual void setColorSectionInternal( int SectInd, Quantity_Color theNewColor ); + + virtual Quantity_Color getLastRemovedColor() const; + + virtual void popLastRemovedColor(); + + //! Gets color of section by index + virtual Quantity_Color getColorSection( int SectInd ) const; + //! Returns specifyed section name virtual std::string getSectionName( const int theISection ) const; @@ -305,6 +319,8 @@ public: */ virtual Handle(AIS_InteractiveObject) getAISObject( const bool theNeedToBuild = false) const; + + protected: /** * Removes the points from the section. It sortes the points and remove them @@ -327,6 +343,8 @@ protected: protected: bool mySkipSorting; + AIS_Shape* myAISShape; //!< AIS shape + public: bool myIsLocked; @@ -334,7 +352,7 @@ public: CurveCreator::Dimension myDimension; //!< curve dimension CurveCreator_Displayer* myDisplayer; //!< curve displayer Quantity_Color myPointAspectColor; - Quantity_Color myCurveColor; + //Quantity_Color myCurveColor; double myLineWidth; private: @@ -345,8 +363,8 @@ private: ListDiff myListDiffs; int myUndoDepth; int myOpLevel; - AIS_Shape* myAISShape; //!< AIS shape bool myEraseAll; + std::vector myRemColors; }; #endif diff --git a/src/CurveCreator/CurveCreator_Diff.cxx b/src/CurveCreator/CurveCreator_Diff.cxx index 362e451e4..a0eeb404d 100644 --- a/src/CurveCreator/CurveCreator_Diff.cxx +++ b/src/CurveCreator/CurveCreator_Diff.cxx @@ -22,6 +22,8 @@ #include "CurveCreator_Diff.hxx" #include "CurveCreator_Curve.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Utils.hxx" #include @@ -171,6 +173,36 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, return isOK; } +bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2[3]) +{ + bool isOK = false; + + if (theCurve != NULL) + { + clear(); + myPRedo = new CurveCreator_Operation; + + if (myPRedo->init(theType, theIntParam1, theIntParam2)) + { + Quantity_Color aColor = theCurve->getColorSection(theIntParam1); + + setNbUndos(1); + QColor aQColor = CurveCreator_Utils::colorConv(aColor); + int colorArr[3] = {aQColor.red(),aQColor.green(), aQColor.blue()}; + + isOK = myPUndo[0].init(theType, theIntParam1, colorArr); + } + + if (!isOK) + clear(); + } + + return isOK; +} + //======================================================================= // function: init // purpose: diff --git a/src/CurveCreator/CurveCreator_Diff.hxx b/src/CurveCreator/CurveCreator_Diff.hxx index 9be05a9db..959729b5c 100644 --- a/src/CurveCreator/CurveCreator_Diff.hxx +++ b/src/CurveCreator/CurveCreator_Diff.hxx @@ -157,6 +157,20 @@ public: bool init(const CurveCreator_Curve *theCurve, const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList); + + /** + * This method initializes the difference with an operation with one + * integer and one array of integer[3] parameters. + * It is applicable to the following operations: + *
    + *
  • ColorSection
  • + *
+ */ + bool init(const CurveCreator_Curve *theCurve, + const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2[3]); + /** * This method applies undo operation to theCurve. */ diff --git a/src/CurveCreator/CurveCreator_Operation.cxx b/src/CurveCreator/CurveCreator_Operation.cxx index 81f776f74..6efcdeb05 100644 --- a/src/CurveCreator/CurveCreator_Operation.cxx +++ b/src/CurveCreator/CurveCreator_Operation.cxx @@ -23,6 +23,9 @@ #include "CurveCreator_Operation.hxx" #include "CurveCreator_Curve.hxx" #include "CurveCreator.hxx" +#include "CurveCreator_Section.hxx" +#include "CurveCreator_Utils.hxx" +#include #include #include @@ -114,6 +117,28 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, return isOK; } +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const int theIntParam1, + const int theIntParam2[3]) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::SetColorSection) + { + int *pData = (int *)allocate(4*sizeof(int)); + + pData[0] = theIntParam1; + pData[1] = theIntParam2[0]; + pData[2] = theIntParam2[1]; + pData[3] = theIntParam2[2]; + myType = theType; + isOK = true; + } + + return isOK; +} + + //======================================================================= // function: Constructor // purpose: @@ -414,7 +439,9 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) char* aPtr = ((char*)&pInt[2]); aPtr += (aName.length()) + 1; getCoords((int*)aPtr, aCoords); - theCurve->addSectionInternal(aName, aType, (pInt[1] != 0), aCoords); + Quantity_Color aLastColor = theCurve->getLastRemovedColor(); + theCurve->popLastRemovedColor(); + theCurve->addSectionInternal(aName, aType, (pInt[1] != 0), aCoords, aLastColor); } break; case CurveCreator_Operation::RemoveSection: @@ -426,6 +453,13 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) theCurve->setSectionNameInternal(pInt[0], aName); } break; + case CurveCreator_Operation::SetColorSection: + { + Quantity_Color aColor = CurveCreator_Utils::colorConv(QColor(pInt[1], pInt[2], pInt[3])); + theCurve->setColorSectionInternal(pInt[0], aColor); + //theCurve->redisplayCurve(false); + } + break; default: break; } diff --git a/src/CurveCreator/CurveCreator_Operation.hxx b/src/CurveCreator/CurveCreator_Operation.hxx index e9e566bf6..f42e0f48d 100644 --- a/src/CurveCreator/CurveCreator_Operation.hxx +++ b/src/CurveCreator/CurveCreator_Operation.hxx @@ -59,7 +59,9 @@ public: Join, //!< Method CurveCreator_Curve::join AddSection, //!< Method CurveCreator_Curve::addSection RemoveSection, //!< Method CurveCreator_Curve::removeSection - RenameSection //!< Method CurveCreator_Curve::renameSection + RenameSection, //!< Method CurveCreator_Curve::renameSection + SetColorSection //!< Method CurveCreator_Curve::setColorSection + }; /** @@ -106,6 +108,14 @@ public: bool init(const Type theType, const int theIntParam1, const int theIntParam2); + /** + * This method initializes the object with an operation with 4 integer + * parameter (1 as first param + 3 as interger array) + */ + bool init(const Type theType, const int theIntParam1, + const int theIntParam2[3]); + + /** * This method initializes the object with an operation with two integer * parameters. It is applicable to the following operations: diff --git a/src/CurveCreator/CurveCreator_Section.hxx b/src/CurveCreator/CurveCreator_Section.hxx index 07b1bc973..3ad9376a2 100644 --- a/src/CurveCreator/CurveCreator_Section.hxx +++ b/src/CurveCreator/CurveCreator_Section.hxx @@ -33,13 +33,15 @@ struct CURVECREATOR_EXPORT CurveCreator_Section : public CurveCreator_ISection { //! Constructor. Initializes object with default values. - CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), myIsClosed(false) + CurveCreator_Section() : myName("Section"),myType(CurveCreator::Polyline), + myIsClosed(false), myColor (Quantity_NOC_RED) { } std::string myName; //!< section name CurveCreator::Coordinates myPoints; //!< points coordinates CurveCreator::SectionType myType; //!< type of the section bool myIsClosed; //!< closed or not + Quantity_Color myColor; //!< color of section //! A virtual method. Handle(TColgp_HArray1OfPnt) GetDifferentPoints( int theDimension ) const; diff --git a/src/CurveCreator/CurveCreator_TreeView.cxx b/src/CurveCreator/CurveCreator_TreeView.cxx index 89f2606c3..e8b2504e9 100644 --- a/src/CurveCreator/CurveCreator_TreeView.cxx +++ b/src/CurveCreator/CurveCreator_TreeView.cxx @@ -19,6 +19,8 @@ #include "CurveCreator_TreeView.h" #include "CurveCreator_ICurve.hxx" +#include "CurveCreator_Curve.hxx" +#include "CurveCreator_Utils.hxx" #include #include @@ -28,8 +30,8 @@ #define ID_SECTION -1 -CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ) : - QAbstractItemModel(parent), myCurve(theCurve) +CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent, bool toDrawColorIcon ) : + QAbstractItemModel(parent), myCurve(theCurve), myDrawColorIcon(toDrawColorIcon) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); QPixmap aSplineIcon(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE"))); @@ -65,8 +67,8 @@ CurveCreator_TreeViewModel::CurveCreator_TreeViewModel( CurveCreator_ICurve* the int CurveCreator_TreeViewModel::columnCount(const QModelIndex & parent ) const { - if( parent.internalId() == ID_SECTION ) - return 2; + if( myDrawColorIcon ) + return 3; else return 2; } @@ -104,6 +106,13 @@ QVariant CurveCreator_TreeViewModel::data(const QModelIndex & index, int role ) } } } + else if (myDrawColorIcon && aColumn == 2) + { + Quantity_Color color = ((CurveCreator_Curve*)myCurve)->getColorSection(aRow); + QPixmap pixmap(16,16); + pixmap.fill( CurveCreator_Utils::colorConv(color)); + return pixmap; + } } } /* else{ @@ -223,7 +232,7 @@ void CurveCreator_TreeViewModel::setCurve( CurveCreator_ICurve* theCurve ) } /*****************************************************************************************/ -CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent) : +CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent, bool toDrawColorIcon) : QTreeView(parent) { header()->hide(); @@ -234,7 +243,7 @@ CurveCreator_TreeView::CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWi #endif setUniformRowHeights(true); setContextMenuPolicy( Qt::CustomContextMenu ); - CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this); + CurveCreator_TreeViewModel* aModel = new CurveCreator_TreeViewModel(theCurve, this, toDrawColorIcon); setModel(aModel); setSelectionBehavior(SelectRows); setSelectionMode(SingleSelection); diff --git a/src/CurveCreator/CurveCreator_TreeView.h b/src/CurveCreator/CurveCreator_TreeView.h index 821a5e550..183dc27f3 100644 --- a/src/CurveCreator/CurveCreator_TreeView.h +++ b/src/CurveCreator/CurveCreator_TreeView.h @@ -28,7 +28,7 @@ class CurveCreator_ICurve; class CurveCreator_TreeViewModel : public QAbstractItemModel { public: - CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent ); + CurveCreator_TreeViewModel( CurveCreator_ICurve* theCurve, QObject* parent, bool toDrawColorIcon ); virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; @@ -50,6 +50,7 @@ private: enum IconType{ ICON_POLYLINE, ICON_SPLINE, ICON_CLOSED_SPLINE, ICON_CLOSED_POLYLINE, ICON_POINT }; private: CurveCreator_ICurve* myCurve; + bool myDrawColorIcon; QMap myCachedIcons; }; @@ -59,7 +60,7 @@ class CurveCreator_TreeView : public QTreeView public: enum SelectionType{ ST_NOSEL, ST_POINTS, ST_POINTS_ONE_SECTION, ST_SECTIONS, ST_MIXED }; public: - explicit CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent = 0); + explicit CurveCreator_TreeView( CurveCreator_ICurve* theCurve, QWidget *parent = 0, bool toDrawColorIcon = true); SelectionType getSelectionType() const; QList getSelectedSections() const; diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 6408b38dc..df5bdd714 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -294,7 +294,8 @@ TopoDS_Wire CurveCreator_Utils::ConstructWire( // purpose : //======================================================================= void CurveCreator_Utils::constructShape( - const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape) + const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape, + std::map* theSect2Wire ) { BRep_Builder aBuilder; TopoDS_Compound aShape; @@ -326,6 +327,11 @@ void CurveCreator_Utils::constructShape( if (!aWire.IsNull()) { aBuilder.Add(aShape, aWire); + if (theSect2Wire) + { + CurveCreator_Section* aSection = (CurveCreator_Section*)theCurve->getSection(aSectionI); + (*theSect2Wire)[aSection] = aWire; + } } } theShape = aShape; @@ -344,6 +350,33 @@ struct Section3D Handle(TColgp_HArray1OfPnt) myPoints; }; +Quantity_Color CurveCreator_Utils::getRandColor() +{ + float aHue = ( rand()%1000 ) * 0.001f; + + QColor aColor; + aColor.setHsl( (int)(aHue*255.), 200, 128 ); + int r = aColor.red(); + int g = aColor.green(); + int b = aColor.blue(); + + double r1 = r / 255.0; + double g1 = g / 255.0; + double b1 = b / 255.0; + return Quantity_Color( r1, g1, b1, Quantity_TOC_RGB ); +} + +Quantity_Color CurveCreator_Utils::colorConv(QColor color) +{ + return Quantity_Color( color.red() / 255., + color.green() / 255., color.blue() / 255., Quantity_TOC_RGB ); +} + +QColor CurveCreator_Utils::colorConv(Quantity_Color color) +{ + return QColor( (int)( color.Red() * 255 ), (int)( color.Green() * 255 ), (int)( color.Blue() * 255 ) ); +} + //======================================================================= // function : constructCurve // purpose : @@ -516,7 +549,7 @@ bool CurveCreator_Utils::constructCurve CurveCreator::Spline : CurveCreator::Polyline; theCurve->addSectionInternal(aSecName, aSecType, - aSecIt->myIsClosed, aCoords); + aSecIt->myIsClosed, aCoords, Quantity_NOC_RED); } // Set the local coordinate system. diff --git a/src/CurveCreator/CurveCreator_Utils.hxx b/src/CurveCreator/CurveCreator_Utils.hxx index 5fb3629c3..9110ed02a 100644 --- a/src/CurveCreator/CurveCreator_Utils.hxx +++ b/src/CurveCreator/CurveCreator_Utils.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include // TODO: remove @@ -55,6 +56,21 @@ public: Handle(V3d_View) theView, int& x, int& y ); + /** + * Generates a random color + */ + CURVECREATOR_EXPORT static Quantity_Color getRandColor(); + + /** + * Convert QColor to Quantity_Color + */ + CURVECREATOR_EXPORT static Quantity_Color colorConv(QColor color); + + /** + * Convert Quantity_Color to QColor + */ + CURVECREATOR_EXPORT static QColor colorConv(Quantity_Color color); + /*! * \brief Returns the point clicked in 3D view. * @@ -70,9 +86,11 @@ public: * Generates shape on the curve * \param theCurve a curve object, that contains data * \param theShape a generated shape + * \param Sect2Wire optional out map: section to constructed wire */ CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve, - TopoDS_Shape& theShape ); + TopoDS_Shape& theShape, + std::map* Sect2Wire = NULL); /** * Generates a curve from a shape. diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 8a7feb465..c40a1d0ee 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -24,6 +24,10 @@ #include "CurveCreator_UtilsICurve.hxx" #include "CurveCreator_TableView.h" +#include "CurveCreator_Curve.hxx" +#include "CurveCreator_Section.hxx" +#include + #include #include #include @@ -95,7 +99,10 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, QGroupBox* aSectionGroup = new QGroupBox(tr("SECTION_GROUP_TITLE"),this); - mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup); + + bool toDrawSectColor = !(theActionFlags & DisableSetColor); + + mySectionView = new CurveCreator_TreeView(myCurve, aSectionGroup, toDrawSectColor); mySectionView->setSelectionMode( QTreeView::ExtendedSelection ); connect( mySectionView, SIGNAL(selectionChanged()), this, SLOT( onSelectionChanged() ) ); connect( mySectionView, SIGNAL(sectionEntered(int)), this, SLOT(onEditSection(int)) ); @@ -122,6 +129,7 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, QPixmap aBringTogetherPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_BRING_TOGETHER"))); QPixmap aStepUpPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_UP"))); QPixmap aStepDownPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_ARROW_DOWN"))); + QPixmap aSetColorPixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SETCOLOR"))); QAction* anAct = createAction( UNDO_ID, tr("UNDO"), anUndoPixmap, tr("UNDO_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Z) ); @@ -189,6 +197,13 @@ CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, QKeySequence(Qt::ControlModifier|Qt::Key_Delete ) ); connect(anAct, SIGNAL(triggered()), this, SLOT(onRemove()) ); aTB->addAction(anAct); + + anAct = createAction( SETCOLOR_ID, tr("SETCOLOR"), aSetColorPixmap, tr("SETCOLOR_TLT"), + QKeySequence(Qt::ControlModifier|Qt::Key_C ) ); + connect(anAct, SIGNAL(triggered()), this, SLOT(onSetColor()) ); + + if ( !(theActionFlags & DisableSetColor) ) + aTB->addAction(anAct); anAct = createAction( JOIN_ID, tr("JOIN"), aJoinPixmap, tr("JOIN_TLT"), QKeySequence(Qt::ControlModifier|Qt::Key_Plus ) ); @@ -357,6 +372,8 @@ void CurveCreator_Widget::updateActionsStates() if ( removeEnabled() ) anEnabledAct << REMOVE_ID; QList aSelSections = mySectionView->getSelectedSections(); + if (aSelSections.size() == 1) + anEnabledAct << SETCOLOR_ID; CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); switch( aSelType ){ case CurveCreator_TreeView::ST_NOSEL:{ @@ -683,6 +700,31 @@ void CurveCreator_Widget::onRemove() } } +void CurveCreator_Widget::onSetColor() +{ + if( !myCurve ) + return; + + QList aSections = mySectionView->getSelectedSections(); + if (aSections.size() != 1) + return; + + int aSectNum = aSections[0]; + Quantity_Color aColor = ((CurveCreator_Curve*)myCurve)->getColorSection( aSectNum );; + + QColor aQColor = CurveCreator_Utils::colorConv(aColor); + QColor aNewQColor = QColorDialog::getColor( aQColor, this ); + if( !aNewQColor.isValid() ) + return; + + Quantity_Color aNewColor = CurveCreator_Utils::colorConv(aNewQColor); + + ((CurveCreator_Curve*)myCurve)->setColorSection( aSectNum, aNewColor); + + updateUndoRedo(); +} + + void CurveCreator_Widget::onClearAll() { if( !myCurve ) diff --git a/src/CurveCreator/CurveCreator_Widget.h b/src/CurveCreator/CurveCreator_Widget.h index e91e50249..9897edc78 100644 --- a/src/CurveCreator/CurveCreator_Widget.h +++ b/src/CurveCreator/CurveCreator_Widget.h @@ -56,7 +56,8 @@ public: NoFlags = 0x00000000, DisableDetectionMode = 0x00000001, DisableNewSection = 0x00000002, - DisableClosedSection = 0x00000004 + DisableClosedSection = 0x00000004, + DisableSetColor = 0x00000008 }; enum ActionMode { @@ -119,6 +120,7 @@ public slots: void onJoin(); void onBringTogether(); void onRemove(); + void onSetColor(); void onClearAll(); void onJoinAll(); void onSetSpline(); @@ -162,7 +164,8 @@ protected: SEPARATOR_ID, MODIFICATION_MODE_ID, DETECTION_MODE_ID, - BRING_TOGETHER_ID + BRING_TOGETHER_ID, + SETCOLOR_ID }; public: diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 4b1c19571..03ffd98e9 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -63,6 +63,10 @@ ICON_CC_UNDO undo.png + + ICON_CC_SETCOLOR + setcolor.png + ICON_FOLDER folder.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index e1010522b..87e293afc 100755 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -6035,6 +6035,14 @@ shells and solids on the other hand. SET_SECTIONS_SPLINE_TLT Set selected section type to spline + + SETCOLOR + Set color + + + SETCOLOR_TLT + Set color + REMOVE Remove From 0d3e4210ae5c8bd0938d64367d4019a544c52759 Mon Sep 17 00:00:00 2001 From: isn Date: Wed, 9 Jan 2019 20:32:28 +0300 Subject: [PATCH 4/5] curveCreator :: allow selection of points of selected polyline(s) only --- src/CurveCreator/CMakeLists.txt | 7 +- src/CurveCreator/CurveCreator_Curve.cxx | 16 ++-- src/CurveCreator/CurveCreator_Curve.hxx | 4 + src/CurveCreator/CurveCreator_Displayer.hxx | 6 ++ src/CurveCreator/CurveCreator_ShapeFilter.cxx | 74 +++++++++++++++++++ src/CurveCreator/CurveCreator_ShapeFilter.hxx | 73 ++++++++++++++++++ src/CurveCreator/CurveCreator_Utils.cxx | 6 +- src/CurveCreator/CurveCreator_Utils.hxx | 3 +- src/CurveCreator/CurveCreator_UtilsICurve.cxx | 1 + src/CurveCreator/CurveCreator_Widget.cxx | 30 ++++++++ 10 files changed, 208 insertions(+), 12 deletions(-) create mode 100644 src/CurveCreator/CurveCreator_ShapeFilter.cxx create mode 100644 src/CurveCreator/CurveCreator_ShapeFilter.hxx diff --git a/src/CurveCreator/CMakeLists.txt b/src/CurveCreator/CMakeLists.txt index ca9625875..3263a1ca2 100644 --- a/src/CurveCreator/CMakeLists.txt +++ b/src/CurveCreator/CMakeLists.txt @@ -26,7 +26,7 @@ ENDIF(SALOME_BUILD_GUI) # additional include directories INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIR} - ${OpenCASCADE_INCLUDE_DIR} + ${CAS_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS} ${GUI_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/src/GEOMUtils @@ -34,12 +34,15 @@ INCLUDE_DIRECTORIES( # additional preprocessor / compiler flags ADD_DEFINITIONS( + ${CAS_DEFINITIONS} ${OpenCASCADE_DEFINITIONS} ${QT_DEFINITIONS} ) # libraries to link to SET(_link_LIBRARIES + ${CAS_KERNEL} + ${CAS_TKernel} GEOMUtils ) IF(SALOME_BUILD_GUI) @@ -66,6 +69,7 @@ ENDIF(SALOME_BUILD_GUI) SET(_other_HEADERS CurveCreator.hxx CurveCreator_Curve.hxx + CurveCreator_ShapeFilter.hxx CurveCreator_Diff.hxx CurveCreator_Displayer.hxx CurveCreator_ICurve.hxx @@ -92,6 +96,7 @@ SET(_other_SOURCES CurveCreator_Curve.cxx CurveCreator_Diff.cxx CurveCreator_Displayer.cxx + CurveCreator_ShapeFilter.cxx CurveCreator_Operation.cxx CurveCreator_Section.cxx CurveCreator_Utils.cxx diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx index 3408e49a9..ca421ef79 100644 --- a/src/CurveCreator/CurveCreator_Curve.cxx +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1067,21 +1068,22 @@ void CurveCreator_Curve::constructAISObject() { //DEBTRACE("constructAISObject"); TopoDS_Shape aShape; - std::map Sect2Wire; - CurveCreator_Utils::constructShape( this, aShape, &Sect2Wire ); + mySect2Wire.Clear(); + CurveCreator_Utils::constructShape( this, aShape, &mySect2Wire ); myAISShape = new AIS_ColoredShape( aShape ); AIS_ColoredShape* AISColoredShape = dynamic_cast(myAISShape); - std::map::iterator it; + std::map::iterator it; - for ( it = Sect2Wire.begin(); it != Sect2Wire.end(); it++ ) + //for ( it = mySect2Wire.begin(); it != mySect2Wire.end(); it++ ) + for (int i = 1; i <= mySect2Wire.Extent(); i++ ) { - CurveCreator_Section* aSect = it->first; + CurveCreator_Section* aSect = (CurveCreator_Section*)getSection(mySect2Wire.FindKey(i)); Quantity_Color aColor = aSect->myColor; - const TopoDS_Shape& aWire = it->second; + const TopoDS_Shape& aWire = mySect2Wire.FindFromIndex(i); AISColoredShape->SetCustomColor(aWire, aColor); } - + // myAISShape->SetColor( myCurveColor ); myAISShape->SetWidth( myLineWidth ); Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect(); diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx index e73a00883..10bbc1870 100644 --- a/src/CurveCreator/CurveCreator_Curve.hxx +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -31,12 +31,14 @@ #include #include +#include struct CurveCreator_Section; class CurveCreator_Displayer; class AIS_Shape; class AIS_InteractiveObject; class Quantity_Color; +class TopoDS_Shape; /** * The CurveCreator_Curve object is represented as one or more sets of @@ -354,6 +356,8 @@ public: Quantity_Color myPointAspectColor; //Quantity_Color myCurveColor; double myLineWidth; + NCollection_IndexedDataMap mySect2Wire; + std::vector myCurSectInd; private: diff --git a/src/CurveCreator/CurveCreator_Displayer.hxx b/src/CurveCreator/CurveCreator_Displayer.hxx index 9528c8616..e43262e7b 100644 --- a/src/CurveCreator/CurveCreator_Displayer.hxx +++ b/src/CurveCreator/CurveCreator_Displayer.hxx @@ -40,6 +40,12 @@ public: void eraseAll( bool isUpdate ); void erase( const Handle(AIS_InteractiveObject)& theObject, bool isUpdate ); void Update(); + + Handle(AIS_InteractiveContext) getContext() + { + return myContext; + } + //void highlight( const AISObjectsList& theObjects, bool isHL ); protected: diff --git a/src/CurveCreator/CurveCreator_ShapeFilter.cxx b/src/CurveCreator/CurveCreator_ShapeFilter.cxx new file mode 100644 index 000000000..d3424b744 --- /dev/null +++ b/src/CurveCreator/CurveCreator_ShapeFilter.cxx @@ -0,0 +1,74 @@ +// Copyright (C) 2013-2019 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_ShapeFilter.cxx +// Author: Ilya Shchekin + + +#include "CurveCreator_ShapeFilter.hxx" + +#include +#include +#include + +IMPLEMENT_STANDARD_RTTIEXT(CurveCreator_ShapeFilter,SelectMgr_Filter) + +CurveCreator_ShapeFilter::CurveCreator_ShapeFilter() +: SelectMgr_Filter() +{ +} + +CurveCreator_ShapeFilter::~CurveCreator_ShapeFilter() +{ +} + +Standard_Boolean CurveCreator_ShapeFilter::ActsOn(const TopAbs_ShapeEnum aType) const +{ + return (aType == TopAbs_VERTEX); +} + +Standard_Boolean CurveCreator_ShapeFilter::IsOk(const Handle(SelectMgr_EntityOwner)& EO) const +{ + Handle(StdSelect_BRepOwner) aBO = Handle(StdSelect_BRepOwner)::DownCast(EO); + if (aBO.IsNull()) + return Standard_False; + + const TopoDS_Shape& aShape = aBO->Shape(); + + if(aShape.ShapeType()!= TopAbs_VERTEX) + return Standard_False; + + return myShapes.Contains(aShape); +} + +void CurveCreator_ShapeFilter::AddShape(const TopoDS_Shape& aShape) +{ + myShapes.Add(aShape); +} + +void CurveCreator_ShapeFilter::RemoveShape(const TopoDS_Shape& aShape) +{ + myShapes.Remove(aShape); +} + +void CurveCreator_ShapeFilter::ClearShapes() +{ + myShapes.Clear(); +} + diff --git a/src/CurveCreator/CurveCreator_ShapeFilter.hxx b/src/CurveCreator/CurveCreator_ShapeFilter.hxx new file mode 100644 index 000000000..cc4912e3a --- /dev/null +++ b/src/CurveCreator/CurveCreator_ShapeFilter.hxx @@ -0,0 +1,73 @@ +// Copyright (C) 2013-2019 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File: CurveCreator_ShapeFilter.hxx +// Author: Ilya Shchekin + + +#ifndef _CurveCreator_ShapeFilter_HeaderFile +#define _CurveCreator_ShapeFilter_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +class SelectMgr_EntityOwner; +class TopoDS_Shape; + + +class CurveCreator_ShapeFilter : public SelectMgr_Filter +{ + +public: + + + Standard_EXPORT CurveCreator_ShapeFilter(); + + Standard_EXPORT ~CurveCreator_ShapeFilter(); + + Standard_EXPORT virtual Standard_Boolean ActsOn (const TopAbs_ShapeEnum aType) const Standard_OVERRIDE; + + Standard_EXPORT virtual Standard_Boolean IsOk (const Handle(SelectMgr_EntityOwner)& EO) const Standard_OVERRIDE; + + Standard_EXPORT void AddShape (const TopoDS_Shape& aShape); + + Standard_EXPORT void RemoveShape (const TopoDS_Shape& aShape); + + Standard_EXPORT void ClearShapes (); + + +private: + + TopTools_MapOfShape myShapes; + +public: + + DEFINE_STANDARD_RTTIEXT(CurveCreator_ShapeFilter,SelectMgr_Filter) + +}; + +DEFINE_STANDARD_HANDLE(CurveCreator_ShapeFilter, SelectMgr_Filter) + +#endif + \ No newline at end of file diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index df5bdd714..24c60320d 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -295,7 +295,7 @@ TopoDS_Wire CurveCreator_Utils::ConstructWire( //======================================================================= void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape, - std::map* theSect2Wire ) + NCollection_IndexedDataMap* theSect2Wire ) { BRep_Builder aBuilder; TopoDS_Compound aShape; @@ -329,8 +329,8 @@ void CurveCreator_Utils::constructShape( aBuilder.Add(aShape, aWire); if (theSect2Wire) { - CurveCreator_Section* aSection = (CurveCreator_Section*)theCurve->getSection(aSectionI); - (*theSect2Wire)[aSection] = aWire; + //CurveCreator_Section* aSection = (CurveCreator_Section*)theCurve->getSection(aSectionI); + (*theSect2Wire).Add(aSectionI, aWire); } } } diff --git a/src/CurveCreator/CurveCreator_Utils.hxx b/src/CurveCreator/CurveCreator_Utils.hxx index 9110ed02a..f773f2317 100644 --- a/src/CurveCreator/CurveCreator_Utils.hxx +++ b/src/CurveCreator/CurveCreator_Utils.hxx @@ -36,6 +36,7 @@ #include #include // TODO: remove +#include class CurveCreator_Curve; @@ -90,7 +91,7 @@ public: */ CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape, - std::map* Sect2Wire = NULL); + NCollection_IndexedDataMap* Sect2Wire = NULL); /** * Generates a curve from a shape. diff --git a/src/CurveCreator/CurveCreator_UtilsICurve.cxx b/src/CurveCreator/CurveCreator_UtilsICurve.cxx index e6e3f9b71..5264cf213 100644 --- a/src/CurveCreator/CurveCreator_UtilsICurve.cxx +++ b/src/CurveCreator/CurveCreator_UtilsICurve.cxx @@ -21,6 +21,7 @@ #include "CurveCreator.hxx" #include +#include const double LOCAL_SELECTION_TOLERANCE = 0.0001; diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index c40a1d0ee..074f03577 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -33,6 +33,9 @@ #include #include +#include +#include "CurveCreator_ShapeFilter.hxx" + #include #include #include @@ -362,6 +365,11 @@ void CurveCreator_Widget::onSelectionChanged() updateActionsStates(); updateUndoRedo(); emit selectionChanged(); + QList selectedSections = mySectionView->getSelectedSections(); + CurveCreator_Curve* Curve = ((CurveCreator_Curve*)myCurve); + Curve->myCurSectInd.clear(); + foreach (int sectInd, selectedSections) + Curve->myCurSectInd.push_back(sectInd); } void CurveCreator_Widget::updateActionsStates() @@ -1158,6 +1166,28 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEven Handle(V3d_View) aView3d = aView->getViewPort()->getView(); if ( !aView3d.IsNull() ) { + CurveCreator_Curve* Curve = ((CurveCreator_Curve*)myCurve); + //if (!Curve->myCurSectInd.empty()) + //{ + aCtx->RemoveFilters(); + Handle(CurveCreator_ShapeFilter) filter = new CurveCreator_ShapeFilter(); + for (int i=0; imyCurSectInd.size(); i++) + { + int sectInd = Curve->myCurSectInd[i]; + const TopoDS_Shape& W = Curve->mySect2Wire(sectInd+1); + TopExp_Explorer exp(W, TopAbs_VERTEX); + for (;exp.More();exp.Next()) + filter->AddShape(exp.Current()); + } + aCtx->AddFilter(filter); + if (aCtx->HasOpenedContext()) + { + Handle(AIS_LocalContext) aLctx = aCtx->LocalContext(); + aLctx->Filter()->Clear(); + aLctx->AddFilter(filter); + } + //} + // Initialize the single selection if start and end points are equal, // otherwise a rectangular selection. if ( myStartPoint == myEndPoint ) From e014eecb1bb25ad1d3e31a1317ba3c3ef13bb4f6 Mon Sep 17 00:00:00 2001 From: isn Date: Thu, 17 Jan 2019 18:18:20 +0300 Subject: [PATCH 5/5] lot 3 : curve creator : allow to move points on spline curve --- src/CurveCreator/CurveCreator_Curve.cxx | 21 +++++++++++++-------- src/CurveCreator/CurveCreator_Curve.hxx | 2 +- src/CurveCreator/CurveCreator_Utils.cxx | 19 ++++++++++++++----- src/CurveCreator/CurveCreator_Utils.hxx | 4 ++-- src/CurveCreator/CurveCreator_Widget.cxx | 2 +- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx index ca421ef79..3c83e673e 100644 --- a/src/CurveCreator/CurveCreator_Curve.cxx +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1063,25 +1064,29 @@ Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISect CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->GetDifferentPoints( (int)myDimension ) : Handle(TColgp_HArray1OfPnt)(); } - void CurveCreator_Curve::constructAISObject() { //DEBTRACE("constructAISObject"); TopoDS_Shape aShape; - mySect2Wire.Clear(); - CurveCreator_Utils::constructShape( this, aShape, &mySect2Wire ); + mySect2Shape.Clear(); + CurveCreator_Utils::constructShape( this, aShape, &mySect2Shape ); myAISShape = new AIS_ColoredShape( aShape ); AIS_ColoredShape* AISColoredShape = dynamic_cast(myAISShape); std::map::iterator it; - //for ( it = mySect2Wire.begin(); it != mySect2Wire.end(); it++ ) - for (int i = 1; i <= mySect2Wire.Extent(); i++ ) + //for ( it = mySect2Shape.begin(); it != mySect2Shape.end(); it++ ) + for (int i = 1; i <= mySect2Shape.Extent(); i++ ) { - CurveCreator_Section* aSect = (CurveCreator_Section*)getSection(mySect2Wire.FindKey(i)); + CurveCreator_Section* aSect = (CurveCreator_Section*)getSection(mySect2Shape.FindKey(i)); Quantity_Color aColor = aSect->myColor; - const TopoDS_Shape& aWire = mySect2Wire.FindFromIndex(i); - AISColoredShape->SetCustomColor(aWire, aColor); + const TopoDS_Shape& aShape = mySect2Shape.FindFromIndex(i); //should contain: one wire + vertices + TopoDS_Iterator it(aShape); + for (;it.More();it.Next()) + { + if (it.Value().ShapeType() == TopAbs_WIRE) + AISColoredShape->SetCustomColor(it.Value(), aColor); + } } // myAISShape->SetColor( myCurveColor ); diff --git a/src/CurveCreator/CurveCreator_Curve.hxx b/src/CurveCreator/CurveCreator_Curve.hxx index 10bbc1870..22caf3f77 100644 --- a/src/CurveCreator/CurveCreator_Curve.hxx +++ b/src/CurveCreator/CurveCreator_Curve.hxx @@ -356,7 +356,7 @@ public: Quantity_Color myPointAspectColor; //Quantity_Color myCurveColor; double myLineWidth; - NCollection_IndexedDataMap mySect2Wire; + NCollection_IndexedDataMap mySect2Shape; std::vector myCurSectInd; private: diff --git a/src/CurveCreator/CurveCreator_Utils.cxx b/src/CurveCreator/CurveCreator_Utils.cxx index 24c60320d..ee4ea6a84 100644 --- a/src/CurveCreator/CurveCreator_Utils.cxx +++ b/src/CurveCreator/CurveCreator_Utils.cxx @@ -295,11 +295,12 @@ TopoDS_Wire CurveCreator_Utils::ConstructWire( //======================================================================= void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape, - NCollection_IndexedDataMap* theSect2Wire ) + NCollection_IndexedDataMap* theSect2Shape ) { BRep_Builder aBuilder; TopoDS_Compound aShape; aBuilder.MakeCompound(aShape); + const int aSectionCount = theCurve->getNbSections(); for (int aSectionI = 0; aSectionI < aSectionCount; ++aSectionI) { @@ -314,10 +315,18 @@ void CurveCreator_Utils::constructShape( const int aPointCount = aPoints->Length(); const bool isClosed = theCurve->isClosed(aSectionI); + TopoDS_Compound ShapeWireWithV; + if (theSect2Shape) + aBuilder.MakeCompound(ShapeWireWithV); + // Add the vertices to the shape. for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN) { - aBuilder.Add(aShape, BRepBuilderAPI_MakeVertex(aPoints->Value(aPN))); + TopoDS_Vertex V; + aBuilder.MakeVertex(V,aPoints->Value(aPN),Precision::Confusion()); + aBuilder.Add(aShape, V); + if (theSect2Shape) + aBuilder.Add(ShapeWireWithV, V); } // Add the wire to the shape. @@ -327,10 +336,10 @@ void CurveCreator_Utils::constructShape( if (!aWire.IsNull()) { aBuilder.Add(aShape, aWire); - if (theSect2Wire) + if (theSect2Shape) { - //CurveCreator_Section* aSection = (CurveCreator_Section*)theCurve->getSection(aSectionI); - (*theSect2Wire).Add(aSectionI, aWire); + aBuilder.Add(ShapeWireWithV, aWire); + (*theSect2Shape).Add(aSectionI, ShapeWireWithV); } } } diff --git a/src/CurveCreator/CurveCreator_Utils.hxx b/src/CurveCreator/CurveCreator_Utils.hxx index f773f2317..3da356778 100644 --- a/src/CurveCreator/CurveCreator_Utils.hxx +++ b/src/CurveCreator/CurveCreator_Utils.hxx @@ -87,11 +87,11 @@ public: * Generates shape on the curve * \param theCurve a curve object, that contains data * \param theShape a generated shape - * \param Sect2Wire optional out map: section to constructed wire + * \param Sect2Shape optional out map: section to constructed shape (wire+vertices) */ CURVECREATOR_EXPORT static void constructShape( const CurveCreator_ICurve* theCurve, TopoDS_Shape& theShape, - NCollection_IndexedDataMap* Sect2Wire = NULL); + NCollection_IndexedDataMap* Sect2Shape = NULL); /** * Generates a curve from a shape. diff --git a/src/CurveCreator/CurveCreator_Widget.cxx b/src/CurveCreator/CurveCreator_Widget.cxx index 074f03577..07b610080 100644 --- a/src/CurveCreator/CurveCreator_Widget.cxx +++ b/src/CurveCreator/CurveCreator_Widget.cxx @@ -1174,7 +1174,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow* theWindow, QMouseEven for (int i=0; imyCurSectInd.size(); i++) { int sectInd = Curve->myCurSectInd[i]; - const TopoDS_Shape& W = Curve->mySect2Wire(sectInd+1); + const TopoDS_Shape& W = Curve->mySect2Shape(sectInd+1); TopExp_Explorer exp(W, TopAbs_VERTEX); for (;exp.More();exp.Next()) filter->AddShape(exp.Current());