X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FCurveCreator%2FCurveCreator_Curve.cxx;h=da46ed11b6461646002cdca755a8a1df491d1563;hb=09ece3edc1896e16a412b35810d76411f06d68ec;hp=e307e81606b14a7c727d9e08613b6e9e2a38f27f;hpb=ec168c32f86cab8199030ec4e8e2b1cbd5e42670;p=modules%2Fgeom.git diff --git a/src/CurveCreator/CurveCreator_Curve.cxx b/src/CurveCreator/CurveCreator_Curve.cxx index e307e8160..da46ed11b 100644 --- a/src/CurveCreator/CurveCreator_Curve.cxx +++ b/src/CurveCreator/CurveCreator_Curve.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2013-2023 CEA, EDF, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -31,11 +31,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include @@ -48,15 +51,19 @@ // purpose: //======================================================================= CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimension ) -: myIsLocked (false), +: mySkipSorting (false), + myIsLocked (false), myDimension (theDimension), myDisplayer (NULL), - myAISShape (NULL), - myNbUndos (0), - myNbRedos (0), + myPointAspectColor (Quantity_NOC_ROYALBLUE4), + //myCurveColor (Quantity_NOC_RED), + myLineWidth (1), + myNbUndos (0), + myNbRedos (0), myUndoDepth (-1), - myOpLevel(0), - mySkipSorting(false) + myOpLevel (0), + myAISShape (NULL), + myEraseAll (true) { } @@ -91,12 +98,12 @@ std::string CurveCreator_Curve::getUniqSectionName() const sprintf( aBuffer, "Section_%d", i+1 ); std::string aName(aBuffer); int j; - for( j = 0 ; j < mySections.size() ; j++ ){ + for( j = 0 ; j < (int)mySections.size() ; j++ ){ aSection = (CurveCreator_Section*)getSection( j ); if ( aSection && aSection->myName == aName ) break; } - if( j == mySections.size() ) + if( j == (int)mySections.size() ) return aName; } return ""; @@ -249,13 +256,16 @@ void CurveCreator_Curve::getCoordinates( int theISection, int theIPoint, double& } } -void CurveCreator_Curve::redisplayCurve() +void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects) { //DEBTRACE("redisplayCurve"); - if( myDisplayer ) { - myDisplayer->eraseAll( false ); + if( myDisplayer ) + { + if (preEraseAllObjects) + myDisplayer->eraseAll( false ); + else + myDisplayer->erase( myAISShape, false); myAISShape = NULL; - myDisplayer->display( getAISObject( true ), true ); } } @@ -357,8 +367,12 @@ bool CurveCreator_Curve::redo() bool CurveCreator_Curve::clearInternal() { // erase curve from the viewer - if( myDisplayer ) { - myDisplayer->eraseAll( true ); + if( myDisplayer ) + { + if (myEraseAll) + myDisplayer->eraseAll( true ); + else + myDisplayer->erase(myAISShape, false); myAISShape = NULL; } // Delete all allocated data. @@ -373,7 +387,7 @@ bool CurveCreator_Curve::clearInternal() } mySections.clear(); - + return true; } @@ -394,6 +408,23 @@ bool CurveCreator_Curve::clear() return res; } +//======================================================================= +// function: clear +// purpose: +//======================================================================= +void CurveCreator_Curve::SetEraseAllState(bool toEraseAll) +{ + myEraseAll = toEraseAll; +} +//======================================================================= +// function: clear +// purpose: +//======================================================================= +bool CurveCreator_Curve::GetEraseAllState() const +{ + return myEraseAll; +} + //! For internal use only! Undo/Redo are not used here. bool CurveCreator_Curve::joinInternal( const std::list& theSections ) { @@ -422,7 +453,7 @@ bool CurveCreator_Curve::joinInternal( const std::list& theSections ) break; } - redisplayCurve(); + redisplayCurve(false); return res; } @@ -452,7 +483,8 @@ int CurveCreator_Curve::getNbSections() const //! For internal use only! Undo/Redo are not used here. int CurveCreator_Curve::addSectionInternal (const std::string& theName, const CurveCreator::SectionType theType, - const bool theIsClosed, const CurveCreator::Coordinates &thePoints) + const bool theIsClosed, const CurveCreator::Coordinates &thePoints, + const Quantity_Color& aColor) { CurveCreator_Section *aSection = new CurveCreator_Section; @@ -464,8 +496,9 @@ int CurveCreator_Curve::addSectionInternal aSection->myType = theType; aSection->myIsClosed = theIsClosed; aSection->myPoints = thePoints; + aSection->myColor = aColor;//getRandColor(); //TODO temp mySections.push_back(aSection); - redisplayCurve(); + redisplayCurve(false); return mySections.size()-1; } @@ -486,7 +519,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; @@ -507,7 +542,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; @@ -517,18 +552,21 @@ int CurveCreator_Curve::addSection bool CurveCreator_Curve::removeSectionInternal( const int theISection ) { 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); } - redisplayCurve(); + redisplayCurve(false); return true; } - + //! Removes the given sections. bool CurveCreator_Curve::removeSection( const int theISection ) { @@ -544,6 +582,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). @@ -604,7 +685,7 @@ bool CurveCreator_Curve::isClosed( const int theISection ) const } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setClosedInternal( const int theISection, +bool CurveCreator_Curve::setClosedInternal( const int theISection, const bool theIsClosed ) { CurveCreator_Section* aSection = 0; @@ -616,14 +697,14 @@ bool CurveCreator_Curve::setClosedInternal( const int theISection, aSection = (CurveCreator_Section*)getSection( i ); if( aSection ) { aSection->myIsClosed = theIsClosed; - redisplayCurve(); + redisplayCurve(false); } } } else { aSection = (CurveCreator_Section*)getSection( theISection ); if ( aSection ) { aSection->myIsClosed = theIsClosed; - redisplayCurve(); + redisplayCurve(false); } } return true; @@ -633,7 +714,7 @@ bool CurveCreator_Curve::setClosedInternal( const int theISection, * Set "closed" flag of the specified section (all sections if * \a theISection is -1). */ -bool CurveCreator_Curve::setClosed( const int theISection, +bool CurveCreator_Curve::setClosed( const int theISection, const bool theIsClosed ) { bool res = false; @@ -656,7 +737,7 @@ std::string CurveCreator_Curve::getSectionName( const int theISection ) const } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setSectionNameInternal( const int theISection, +bool CurveCreator_Curve::setSectionNameInternal( const int theISection, const std::string& theName ) { bool res = false; @@ -669,7 +750,7 @@ bool CurveCreator_Curve::setSectionNameInternal( const int theISection, } /** Set name of the specified section */ -bool CurveCreator_Curve::setSectionName( const int theISection, +bool CurveCreator_Curve::setSectionName( const int theISection, const std::string& theName ) { bool res = false; @@ -693,7 +774,7 @@ CurveCreator::SectionType CurveCreator_Curve::getSectionType } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, +bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, const CurveCreator::SectionType theType ) { CurveCreator_Section* aSection; @@ -706,12 +787,12 @@ bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, if ( aSection ) aSection->myType = theType; } - redisplayCurve(); + redisplayCurve(false); } else { aSection = (CurveCreator_Section*)getSection( theISection ); if ( aSection && aSection->myType != theType ){ aSection->myType = theType; - redisplayCurve(); + redisplayCurve(false); } } return true; @@ -721,7 +802,7 @@ bool CurveCreator_Curve::setSectionTypeInternal( const int theISection, * Set type of the specified section (or all sections * if \a theISection is -1). */ -bool CurveCreator_Curve::setSectionType( const int theISection, +bool CurveCreator_Curve::setSectionType( const int theISection, const CurveCreator::SectionType theType ) { bool res = false; @@ -763,8 +844,8 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the anIterPosition = aSection->myPoints.end(); else anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt); - CurveCreator::Coordinates::const_iterator aFirstPosition = - aCoords.begin(); + /*CurveCreator::Coordinates::const_iterator aFirstPosition = + aCoords.begin();*/ aSection->myPoints.insert(anIterPosition, aCoords.begin(), aCoords.end()); } @@ -772,7 +853,7 @@ bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &the } } if(res) - redisplayCurve(); + redisplayCurve(false); return res; } @@ -817,7 +898,7 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS for ( ; anIt != theSectionsMap.end(); anIt++ ) { int anISection = anIt->first; aSection = (CurveCreator_Section*)getSection( anISection ); - if( aSection ) { + if( aSection ) { CurveCreator::PosPointsList aSectionPoints = anIt->second; CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ @@ -830,8 +911,8 @@ bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theS } } if(res) - redisplayCurve(); - + redisplayCurve(false); + return res; } @@ -856,13 +937,13 @@ bool CurveCreator_Curve::setPoint( const int theISection, aPoints.push_back( aPosPoint ); aSectionsMap[theISection] = aPoints; - int aSize1 = getNbPoints( theISection ); + /*int aSize1 = */getNbPoints( theISection ); // todo: unused variable res = setPointInternal( aSectionsMap ); - int aSize2 = getNbPoints( theISection ); + /*int aSize2 = */getNbPoints( theISection ); // todo: unused variable finishOperation(); - return res; + return res; } //! Set coordinates of specified points from different sections @@ -879,7 +960,7 @@ bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSe } CurveCreator::SectionsMap aSectionsMap; CurveCreator::PosPointsList aPosPoints; - CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end(); int aSectionId, aPointId; for ( ; anIt != aLast; anIt++ ) { @@ -887,18 +968,18 @@ bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSe aSectionId = anIt->first.first; aPointId = anIt->first.second; CurveCreator::Coordinates aNewCoords = anIt->second; - CurveCreator_PosPoint* aPosPoint = + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aNewCoords ); if( aSectionsMap.find(aSectionId) != aSectionsMap.end() ) aPosPoints = aSectionsMap[aSectionId]; aPosPoints.push_back( aPosPoint ); aSectionsMap[aSectionId] = aPosPoints; - + } res = setPointInternal( aSectionsMap ); finishOperation(); - return res; + return res; } //! For internal use only! Undo/Redo are not used here. @@ -914,7 +995,7 @@ bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoin aRes = removeSectionPoints(aSectionId, anIt->second); } if( aRes) - redisplayCurve(); + redisplayCurve(false); return aRes; } @@ -971,32 +1052,58 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, // function: getPoints // purpose: //======================================================================= -CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const +CurveCreator::Coordinates CurveCreator_Curve::getCoords( int theISection ) const { - //DEBTRACE("getPoints"); CurveCreator_Section* aSection = (CurveCreator_Section*)getSection( theISection ); return aSection ? aSection->myPoints : CurveCreator::Coordinates(); } +Handle(TColgp_HArray1OfPnt) CurveCreator_Curve::GetDifferentPoints( int theISection ) const +{ + //DEBTRACE("getPoints"); + 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; - CurveCreator_Utils::constructShape( this, aShape ); + 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 = mySect2Shape.begin(); it != mySect2Shape.end(); it++ ) + for (int i = 1; i <= mySect2Shape.Extent(); i++ ) + { + CurveCreator_Section* aSect = (CurveCreator_Section*)getSection(mySect2Shape.FindKey(i)); + Quantity_Color aColor = aSect->myColor; + 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 = new AIS_Shape( aShape ); + // myAISShape->SetColor( myCurveColor ); + myAISShape->SetWidth( myLineWidth ); Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect(); anAspect->SetScale( 3.0 ); anAspect->SetTypeOfMarker(Aspect_TOM_O_POINT); - anAspect->SetColor(Quantity_NOC_ROYALBLUE4); + anAspect->SetColor(myPointAspectColor); myAISShape->Attributes()->SetPointAspect( anAspect ); - } Handle(AIS_InteractiveObject) CurveCreator_Curve::getAISObject( const bool theNeedToBuild ) const { //DEBTRACE("getAISObject"); - if ( !myAISShape && theNeedToBuild ) { + if ( !myAISShape && theNeedToBuild ) + { CurveCreator_Curve* aCurve = (CurveCreator_Curve*)this; aCurve->constructAISObject(); }