]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Hydro lots 3/8
authorisn <isn@opencascade.com>
Tue, 25 Sep 2018 10:24:25 +0000 (13:24 +0300)
committerisn <isn@opencascade.com>
Thu, 11 Oct 2018 11:49:30 +0000 (14:49 +0300)
17 files changed:
resources/CMakeLists.txt
resources/setcolor.png [new file with mode: 0644]
src/CurveCreator/CurveCreator_Curve.cxx
src/CurveCreator/CurveCreator_Curve.hxx
src/CurveCreator/CurveCreator_Diff.cxx
src/CurveCreator/CurveCreator_Diff.hxx
src/CurveCreator/CurveCreator_Operation.cxx
src/CurveCreator/CurveCreator_Operation.hxx
src/CurveCreator/CurveCreator_Section.hxx
src/CurveCreator/CurveCreator_TreeView.cxx
src/CurveCreator/CurveCreator_TreeView.h
src/CurveCreator/CurveCreator_Utils.cxx
src/CurveCreator/CurveCreator_Utils.hxx
src/CurveCreator/CurveCreator_Widget.cxx
src/CurveCreator/CurveCreator_Widget.h
src/GEOMGUI/GEOM_images.ts
src/GEOMGUI/GEOM_msg_en.ts

index 74be117a6d15f13d519b69f81eb98a142d407985..ff1e39d944425c065e9f18710c59e2d260b6a2b5 100755 (executable)
@@ -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 (file)
index 0000000..15b9545
Binary files /dev/null and b/resources/setcolor.png differ
index 35843c83a7b8ec70dcbf16942592ba4eee3fe545..3408e49a9c2724de7a5b1a90dee693dd91c60cf8 100644 (file)
@@ -36,7 +36,7 @@
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Face.hxx>
 #include <TopoDS_Wire.hxx>
-
+#include <AIS_ColoredShape.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <iostream>
 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
@@ -58,7 +58,7 @@ CurveCreator_Curve::CurveCreator_Curve( const CurveCreator::Dimension theDimensi
   myOpLevel(0),
   mySkipSorting(false),
   myPointAspectColor (Quantity_NOC_ROYALBLUE4), 
-  myCurveColor (Quantity_NOC_RED),
+  //myCurveColor (Quantity_NOC_RED),
   myEraseAll(true),
   myLineWidth(1)
 {
@@ -480,7 +480,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;
 
@@ -492,6 +493,7 @@ int CurveCreator_Curve::addSectionInternal
   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;
@@ -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<CurveCreator_Section*, TopoDS_Shape> Sect2Wire;
+  CurveCreator_Utils::constructShape( this, aShape, &Sect2Wire );
+  myAISShape = new AIS_ColoredShape( aShape ); 
+  AIS_ColoredShape* AISColoredShape = dynamic_cast<AIS_ColoredShape*>(myAISShape);
+
+  std::map<CurveCreator_Section*, TopoDS_Shape>::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 );
index 08239f4e7564c78761dbbb9ea198526644818a46..e73a00883dba1cfbb502d961c96aeb9f3a330793 100644 (file)
@@ -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<Quantity_Color>     myRemColors;
 };
 
 #endif
index 362e451e4c2fbf752e565536f812ed9b72bc6678..a0eeb404ddf21d96f466cc932fce1ba0471b28c8 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "CurveCreator_Diff.hxx"
 #include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Section.hxx"
+#include "CurveCreator_Utils.hxx"
 
 #include <list>
 
@@ -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:
index 9be05a9db3d35f36394775aae65447aa56740311..959729b5ceae509b9d7a09eadcb944e0c82dda95 100644 (file)
@@ -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:
+   * <UL>
+   *   <LI>ColorSection</LI>
+   * </UL>
+   */
+  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.
    */
index 81f776f742da4f137582f1365b3b7218ed16c3c7..6efcdeb050dbeed998b2bc5b3fa49366c1b92836 100644 (file)
@@ -23,6 +23,9 @@
 #include "CurveCreator_Operation.hxx"
 #include "CurveCreator_Curve.hxx"
 #include "CurveCreator.hxx"
+#include "CurveCreator_Section.hxx"
+#include "CurveCreator_Utils.hxx"
+#include <QColor>
 
 #include <string>
 #include <stdlib.h>
@@ -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;
     }
index e9e566bf6ed9792d52e890df864250a6acc64e6e..f42e0f48d0277f279e3c8545e9472ed004a3bbcd 100644 (file)
@@ -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:
index 07b1bc9731309da0fbe70a75f42c008b1ea81d98..3ad9376a269474f38e2f386a2b165af7587a8ad4 100644 (file)
@@ -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;
index 89f2606c3586f3eb1832f526c465a87b8dd68a37..e8b2504e96fac98c881cc85840722e18c56660b1 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "CurveCreator_TreeView.h"
 #include "CurveCreator_ICurve.hxx"
+#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Utils.hxx"
 
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
@@ -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);
index 821a5e5506054ddcecdeaeb57d82db32fdc90d3d..183dc27f31353559f0aa0d494fdb2882e5aeebda 100644 (file)
@@ -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<IconType, QPixmap>      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<int> getSelectedSections() const;
 
index 6408b38dc705d63231a5dffd67f820ac42258ce8..df5bdd714821a14e7efad5bc3bcf8d800499b98a 100644 (file)
@@ -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<CurveCreator_Section*, TopoDS_Shape>* 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.
index 5fb3629c3ff7bf8c48ee30e6056e947de8531a18..9110ed02a5bb2d23bb118871dd4d35f7bc231f07 100644 (file)
@@ -32,6 +32,7 @@
 #include <TopoDS_Wire.hxx>
 #include <TColgp_HArray1OfPnt.hxx>
 #include <Geom_BSplineCurve.hxx>
+#include <QColor>
 
 #include <list>
 #include <vector> // 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<CurveCreator_Section*, TopoDS_Shape>* Sect2Wire = NULL);
 
   /**
    * Generates a curve from a shape.
index 8a7feb465f0b3c1df3bec85855ce94e5866a8435..c40a1d0ee044db4aa02c5ff714caed6c450e2999 100644 (file)
 #include "CurveCreator_UtilsICurve.hxx"
 #include "CurveCreator_TableView.h"
 
+#include "CurveCreator_Curve.hxx"
+#include "CurveCreator_Section.hxx"
+#include <QColorDialog>
+
 #include <SUIT_Session.h>
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
@@ -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<int> 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<int> 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 )
index e91e50249f27a1ec4dbd19a1d19e9e559f9d2fdc..9897edc78f0a1f1496936f989a8ed0588309d9dd 100644 (file)
@@ -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:
index 4b1c19571d8d41262e7088c7fb5cee0736c59704..03ffd98e9e2ef25b5d77f3e0387a22dbf5047275 100644 (file)
             <source>ICON_CC_UNDO</source>
             <translation>undo.png</translation>
         </message>
+        <message>
+            <source>ICON_CC_SETCOLOR</source>
+            <translation>setcolor.png</translation>
+        </message>
         <message>
             <source>ICON_FOLDER</source>
             <translation>folder.png</translation>
index e1010522be759e25bcbed481fa428bc6f40fe137..87e293afcc933e156a4c2151da9a7b7d379e9ad3 100755 (executable)
@@ -6035,6 +6035,14 @@ shells and solids on the other hand.</translation>
         <source>SET_SECTIONS_SPLINE_TLT</source>
         <translation>Set selected section type to spline</translation>
     </message>
+    <message>
+        <source>SETCOLOR</source>
+        <translation>Set color</translation>
+    </message>
+    <message>
+        <source>SETCOLOR_TLT</source>
+        <translation>Set color</translation>
+    </message>
     <message>
         <source>REMOVE</source>
         <translation>Remove</translation>