-// Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2024 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
#include <AIS_Shape.hxx>
#include <AIS_InteractiveObject.hxx>
#include <Geom_CartesianPoint.hxx>
+#include <TopoDS_Iterator.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Wire.hxx>
+#include <TopoDS_Shape.hxx>
+#include <AIS_ColoredShape.hxx>
#include <Prs3d_PointAspect.hxx>
#include <iostream>
// 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),
- myPointAspectColor (Quantity_NOC_ROYALBLUE4),
- myCurveColor (Quantity_NOC_RED),
- myEraseAll(true),
- myLineWidth(1)
+ myOpLevel (0),
+ myAISShape (NULL),
+ myEraseAll (true)
{
}
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 "";
void CurveCreator_Curve::redisplayCurve(bool preEraseAllObjects)
{
//DEBTRACE("redisplayCurve");
- if( myDisplayer )
+ if( myDisplayer )
{
if (preEraseAllObjects)
myDisplayer->eraseAll( false );
}
mySections.clear();
-
+
return true;
}
//! 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;
aSection->myType = theType;
aSection->myIsClosed = theIsClosed;
aSection->myPoints = thePoints;
+ aSection->myColor = aColor;//getRandColor(); //TODO temp
mySections.push_back(aSection);
redisplayCurve(false);
return mySections.size()-1;
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;
theName, thePoints, theType, theIsClosed);
}
- resISection = addSectionInternal(theName, theType, theIsClosed, thePoints);
+ resISection = addSectionInternal(theName, theType, theIsClosed, thePoints, Quantity_NOC_YELLOW);
finishOperation();
return resISection;
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(false);
return true;
}
-
+
//! Removes the given sections.
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).
}
//! 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;
* 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;
}
//! 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;
}
/** 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;
}
//! 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;
* 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;
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());
}
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++ ){
}
if(res)
redisplayCurve(false);
-
+
return res;
}
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
}
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++ ) {
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.
{
//DEBTRACE("constructAISObject");
TopoDS_Shape aShape;
- CurveCreator_Utils::constructShape( this, aShape );
- myAISShape = new AIS_Shape( aShape );
- myAISShape->SetColor( myCurveColor );
+ mySect2Shape.Clear();
+ CurveCreator_Utils::constructShape( this, aShape, &mySect2Shape );
+ myAISShape = new AIS_ColoredShape( aShape );
+ AIS_ColoredShape* AISColoredShape = dynamic_cast<AIS_ColoredShape*>(myAISShape);
+
+ std::map<int, TopoDS_Shape>::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->SetColor( myCurveColor );
myAISShape->SetWidth( myLineWidth );
Handle(Prs3d_PointAspect) anAspect = myAISShape->Attributes()->PointAspect();
anAspect->SetScale( 3.0 );
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();