Salome HOME
lots 3,8
authorisn <isn@opencascade.com>
Mon, 24 Sep 2018 14:42:48 +0000 (17:42 +0300)
committerisn <isn@opencascade.com>
Thu, 11 Oct 2018 11:18:13 +0000 (14:18 +0300)
Signed-off-by: isn <isn@opencascade.com>
14 files changed:
src/HYDROData/HYDROData_Entity.cxx
src/HYDROData/HYDROData_Entity.h
src/HYDROData/HYDROData_IPolyline.cxx
src/HYDROData/HYDROData_IPolyline.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/HYDROData_Profile.cxx
src/HYDROData/HYDROData_Profile.h
src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx
src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h
src/HYDROGUI/HYDROGUI_PolylineOp.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.h
src/HYDROGUI/HYDROGUI_ProfileOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index a39e125b465d7ffd894dc2c959cb3cf8d33a04d3..cef1e9858eeda5bda18b73d5c8dd2c4bf1876176 100644 (file)
@@ -719,6 +719,25 @@ QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
   return aResColor;
 }
 
+bool HYDROData_Entity::GetColor( QColor& theOutColor,
+                                 const int     theTag ) const
+{
+  TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
+
+  Handle(TDataStd_IntegerArray) aColorArray;
+  if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
+  {
+    theOutColor.setRed(   aColorArray->Value( 1 ) );
+    theOutColor.setGreen( aColorArray->Value( 2 ) );
+    theOutColor.setBlue(  aColorArray->Value( 3 ) );
+    theOutColor.setAlpha( aColorArray->Value( 4 ) );
+    return true;
+  }
+
+  return false;
+}
+
+
 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList;
index bba4f693f77f8f47b1f4fecf52bc106625eadb96..f55fa33acf5ecbc56ec86ecb009dceea6cc8e6c2 100644 (file)
@@ -296,6 +296,14 @@ public:
    * \param theDefColor default color to return if attribute has not been set before
    */
   HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
+
+  /* Internal method that used to retreive the color attribute
+    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
+   * \param theOutColor color to return if attribute has been set before
+   * \return true if attribute is present
+   */
+  HYDRODATA_EXPORT bool GetColor( QColor& theOutColor,
+                                  const int     theTag ) const;
  
 protected:
 
index a0a2fe30fc00b599361d85b2fd3eed62881d2535..3bcb60dc9b8376dca158dacf025dd6793d91670c 100644 (file)
@@ -24,6 +24,7 @@
 #include <TDataStd_ExtStringList.hxx>
 #include <TDataStd_IntegerList.hxx>
 #include <TDataStd_RealList.hxx>
+#include <TDataStd_IntegerArray.hxx>
 #include <TopoDS_Shape.hxx>
 #include <QColor>
 
@@ -166,3 +167,57 @@ void HYDROData_IPolyline::removePointsLists( const int theSectionIndex ) const
       aSectLabel.ForgetAllAttributes();
   }
 }
+
+void HYDROData_IPolyline::getSectionColor( const int theSectionIndex,
+                                           QColor& theColor,
+                                           const bool theIsCreate ) const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, theIsCreate );
+  if ( aLabel.IsNull() )
+    return;
+
+  TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, theIsCreate );
+  if ( aSectLabel.IsNull() )
+    return;
+
+  Handle(TDataStd_IntegerArray) aColorArray;
+  if (theIsCreate)
+  {
+    if ( !aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
+      aColorArray = TDataStd_IntegerArray::Set( aSectLabel, 1, 4 );
+
+    aColorArray->SetValue( 1, theColor.red()   );
+    aColorArray->SetValue( 2, theColor.green() );
+    aColorArray->SetValue( 3, theColor.blue()  );
+    aColorArray->SetValue( 4, theColor.alpha() );
+  }
+  else
+  {
+    Handle(TDataStd_IntegerArray) aColorArray;
+    if ( aSectLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
+    {
+      theColor.setRed(   aColorArray->Value( 1 ) );
+      theColor.setGreen( aColorArray->Value( 2 ) );
+      theColor.setBlue(  aColorArray->Value( 3 ) );
+      theColor.setAlpha( aColorArray->Value( 4 ) );
+    }
+  }
+}
+
+void HYDROData_IPolyline::removeSectionColor( const int theSectionIndex ) const
+{
+  TDF_Label aLabel = myLab.FindChild( DataTag_SectionColors, false );
+  if ( aLabel.IsNull() )
+    return;
+
+  if ( theSectionIndex < 0 )
+  {
+    aLabel.ForgetAllAttributes();
+  }
+  else
+  {
+    TDF_Label aSectLabel = aLabel.FindChild( theSectionIndex, false );
+    if ( !aSectLabel.IsNull() )
+      aSectLabel.ForgetAllAttributes();
+  }
+}
index afb307cb0b68bee4d6fa29809f951b020903d698..cd306e979b759de8abb4741fed1f5174cb2db9c8 100644 (file)
@@ -27,6 +27,7 @@ class TDataStd_RealList;
 class TDataStd_ExtStringList;
 class TDataStd_BooleanList;
 class TDataStd_IntegerList;
+class Quantity_Color;
 
 
 /**\class HYDROData_IPolyline
@@ -51,6 +52,7 @@ protected:
     DataTag_Sections,
     DataTag_PolylineShape,
     DataTag_WireColor,
+    DataTag_SectionColors,
   };
 
 public:
@@ -189,6 +191,12 @@ public:
   HYDRODATA_EXPORT TopoDS_Shape GetShape() const;
   HYDRODATA_EXPORT void SetShape( const TopoDS_Shape& theShape );
 
+  HYDRODATA_EXPORT void getSectionColor( const int                  theSectionIndex,
+                        QColor&            theColor,
+                        const bool                 theIsCreate = true ) const;
+
+  HYDRODATA_EXPORT void removeSectionColor( const int theSectionIndex = -1 ) const;
+
 protected:
   void RemovePolylineShape();
 
@@ -206,6 +214,8 @@ protected:
 
   void removePointsLists( const int theSectionIndex = -1 ) const;
 
+
+
 protected:
 
   /**
index 17cc1e0bdec7df73443acf893b03d441b966d89f..16e02e74551d12ddc8a3dd26712fbcc68df9ceac 100644 (file)
@@ -1281,7 +1281,7 @@ void HYDROData_PolylineXY::RemoveSection( const int theSectionIndex )
     }
 
     // Remove points that belongs to removed section
-    removePointsLists( theSectionIndex );
+    removePointsLists( theSectionIndex ); //TODO remove colors
   }
 
   Changed( Geom_2d );
index 936e95130fbf7acc2a2ea482b1aacda786c38a26..cd8bd084a4152aeaf8ee2bfd36f37e3fef3a9eb0 100644 (file)
@@ -484,6 +484,16 @@ TCollection_AsciiString HYDROData_Profile::GetFilePath() const
   return aRes;
 }
 
+void HYDROData_Profile::SetProfileColor( const QColor& theColor )
+{
+  SetColor( theColor, DataTag_ProfileColor );
+}
+
+bool HYDROData_Profile::GetProfileColor(QColor& outColor) const
+{
+  return GetColor( outColor, DataTag_ProfileColor );
+}
+
 int HYDROData_Profile::ImportFromFile( const Handle(HYDROData_Document)& theDoc,
                                        const TCollection_AsciiString&    theFileName,
                                        NCollection_Sequence<int>&        theBadProfilesIds,
index 658bc8473bf5c801686b47a1199852a35d1517c6..79f241858325a73c177c0a86d3562d2aa8773c77 100644 (file)
@@ -46,7 +46,8 @@ protected:
     DataTag_FirstPoint,       ///< first(left) point
     DataTag_LastPoint,        ///< last(right) point
     DataTag_ChildProfileUZ,   ///< child parametric profile
-    DataTag_FilePath          ///< profile imported file path
+    DataTag_FilePath,          ///< profile imported file path
+    DataTag_ProfileColor      ///< color of profile
   };
 
 public:
@@ -214,6 +215,12 @@ public:
    */
   HYDRODATA_EXPORT TCollection_AsciiString  GetFilePath() const;
 
+
+  HYDRODATA_EXPORT void SetProfileColor( const QColor& theColor );
+
+  HYDRODATA_EXPORT bool GetProfileColor(QColor&) const;
+
+
   /**
    * Imports Profile data from file. The supported file types:
    *  - parametric presentation of profile (2 points in line U,Z)
index 2ef728a665b4799e2d2abb412d20b01fe9c0c9d0..88d6f7c75746b0d82bb8879254b3b9f02fecd1b3 100644 (file)
 #include <CurveCreator_Displayer.hxx>
 #include <CurveCreator_Section.hxx>
 #include <QVector>
+#include <TopoDS_Shape.hxx>
+#include <CurveCreator_Utils.hxx>
+#include <AIS_Shape.hxx>
+#include <Prs3d_PointAspect.hxx>
 
 HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
 : CurveCreator_Curve( CurveCreator::Dim2d )
@@ -28,6 +32,7 @@ HYDROGUI_CurveCreatorProfile::HYDROGUI_CurveCreatorProfile()
   aSection->myName     = getUniqSectionName();
   aSection->myType     = CurveCreator::Polyline;
   aSection->myIsClosed = false;
+  myCurveColor = Quantity_NOC_RED;
 
   mySections.push_back( aSection );
   mySkipSorting = true;
@@ -284,3 +289,18 @@ Handle(TColgp_HArray1OfPnt) HYDROGUI_CurveCreatorProfile::GetDifferentPoints( in
 
   return points;
 }
+/*
+void HYDROGUI_CurveCreatorProfile::constructAISObject()
+{
+  TopoDS_Shape aShape;
+  CurveCreator_Utils::constructShape( this, aShape );
+  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(myPointAspectColor);
+  myAISShape->Attributes()->SetPointAspect( anAspect );
+}*/
+
index 58fd7152b30bba1cb11090d165af2c56b365b45c..e45621d6be75e62284c93c707bba7ac73505f7fe 100644 (file)
@@ -20,6 +20,7 @@
 #define HYDROGUI_CurveCreator_Profile_HeaderFile
 
 #include "CurveCreator_Curve.hxx"
+#include <Quantity_Color.hxx>
 
 /**
  *  The CurveCreator_Curve object is represented as one or more sets of
@@ -115,7 +116,6 @@ public:
   virtual bool addPoints( const CurveCreator::Coordinates &theCoords,
                           const int theISection,
                           const int theIPnt = -1 );
-
   /**
    * Indicates whether the points can be sorted.
    */
@@ -132,6 +132,10 @@ protected:
   void convert( const CurveCreator::PosPointsList& thePoints,
                 std::list<int>& theConvPoints );
 
+  //virtual void constructAISObject();
+
+  Quantity_Color myCurveColor;
+
 };
 
 #endif
index a59af02da79c5366e2075e689443812b797250a9..cbb18cba0c0e210c92299d4872d543cbc62f0855 100755 (executable)
@@ -31,6 +31,7 @@
 
 #include <CurveCreator_Curve.hxx>
 #include <CurveCreator_Displayer.hxx>
+#include <CurveCreator_Utils.hxx>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -182,8 +183,12 @@ void HYDROGUI_PolylineOp::startOperation()
           aCurveCoords.push_back( aSectPoint.Y() );
         }
 
+        Quantity_Color aColor = CurveCreator_Utils::getRandColor();      
+        QColor aQColor = CurveCreator_Utils::colorConv(aColor);
+        myEditedObject->getSectionColor(i-1, aQColor, false);
+
         myCurve->addSectionInternal( aSectName.toStdString(),
-          aCurveType, aSectClosure, aCurveCoords );
+          aCurveType, aSectClosure, aCurveCoords, CurveCreator_Utils::colorConv(aQColor) );
       }
     }
     else
@@ -239,7 +244,7 @@ void HYDROGUI_PolylineOp::startOperation()
         for (int aSI = 0; aSI < aSCount; ++aSI)
         {
           myCurve->addSectionInternal((aNamePrefix + (aSI + 1)).ToCString(),
-            CurveCreator::Spline, isCloseds[aSI], aPs[aSI]);
+            CurveCreator::Spline, isCloseds[aSI], aPs[aSI], CurveCreator_Utils::getRandColor());
         }
       }
     }
@@ -353,6 +358,9 @@ bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
 
     aPolylineObj->AddSection( aSectName, aSectType, aSectClosure );
 
+    Quantity_Color aColor = myCurve->getColorSection(i);
+    aPolylineObj->getSectionColor(i, CurveCreator_Utils::colorConv(aColor), true);
+
     // Add the points from section
     CurveCreator::Coordinates aCurveCoords = myCurve->getCoords( i );
 
index 2fb8b2f6c5fe5aa68bb7bc42693f5b531031e205..6e8479d111eb75ed57c4044e6ed6e974859ba6b6 100644 (file)
@@ -29,6 +29,7 @@
 #include <CurveCreator_ICurve.hxx>
 #include <CurveCreator_Utils.hxx>
 #include <HYDROGUI_CurveCreatorProfile.h>
+#include <HYDROData_Tool.h>
 #include <CurveCreator_Displayer.hxx>
 
 #include <OCCViewer_ViewPort3d.h>
@@ -53,6 +54,7 @@
 #include <QListWidget>
 #include <QPushButton>
 #include <SUIT_MessageBox.h>
+#include <QColorDialog>
 
 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
 
@@ -77,17 +79,26 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
     myProfileNames = new QListWidget(this);
     myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
     name_layout->addWidget(myProfileNames);
+
+    QVBoxLayout* btn_layout = new QVBoxLayout( name_frame );
+    btn_layout->setAlignment(Qt::AlignTop);
+
     myAddProfBtn = new QPushButton(tr("ADD_PROFILES"), this);    
     myRemProfBtn = new QPushButton(tr("REMOVE_PROFILE"), this);
-    name_layout->addWidget(myAddProfBtn);
-    name_layout->addWidget(myRemProfBtn);
+    mySetColorProfBtn = new QPushButton(tr("SETCOLOR_PROFILE"), this);
+    btn_layout->addWidget(myAddProfBtn);
+    btn_layout->addWidget(myRemProfBtn);
+    btn_layout->addWidget(mySetColorProfBtn);
+
+    name_layout->addLayout(btn_layout);
+
   }
 
   insertWidget( name_frame, 0, 0 );
 
   int anActionFlags = 
     CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
-    CurveCreator_Widget::DisableClosedSection;
+    CurveCreator_Widget::DisableClosedSection | CurveCreator_Widget::DisableSetColor;
   QStringList aCoordTitles;
   aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
   myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
@@ -112,6 +123,7 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
     connect( myProfileNames, SIGNAL( itemChanged(QListWidgetItem*)), this, SLOT( onProfileNameChanged(QListWidgetItem*)));
     connect( myAddProfBtn, SIGNAL( clicked(bool)), this, SLOT( onAddBtnPressed(bool)));
     connect( myRemProfBtn, SIGNAL( clicked(bool)), this, SLOT( onRemoveBtnPressed(bool)));
+    connect( mySetColorProfBtn, SIGNAL( clicked(bool)), this, SLOT( onSetColorBtnPressed(bool)));
   }
   myAddElementBox->hide();
 
@@ -331,6 +343,38 @@ void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
     emit RemoveProfile(theIndex);
 }
 
+void HYDROGUI_ProfileDlg::onSetColorBtnPressed(bool)
+{
+  int theIndex = GetProfileSelectionIndex();
+  if (theIndex < 0)
+    return;
+
+  HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[theIndex];
+  
+  QColor aCurrentColor = HYDROData_Tool::toQtColor(/*aCurve->myCurveColor*/aCurve->getColorSection(0));
+  QColor newQCurCol = QColorDialog::getColor( aCurrentColor, this );
+  if( !newQCurCol.isValid() )
+    return;
+
+  Quantity_Color newOCCCol = HYDROData_Tool::toOccColor(newQCurCol);
+  aCurve->setColorSectionInternal(0, newOCCCol);
+  //Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
+  //if (anAISObject)
+  //  anAISObject->SetColor(newOCCCol);
+
+  QListWidgetItem* item = myProfileNames->item(theIndex);
+  QPixmap SPixmap(16, 16);
+  SPixmap.fill(newQCurCol);
+  QIcon SIcon(SPixmap);
+  item->setIcon( SIcon );
+
+  if( myProfilesPointer && 
+    myProfilesPointer->size()>0 && 
+    myProfilesPointer->at(0) && 
+    myProfilesPointer->at(0)->getDisplayer() )
+    myProfilesPointer->at(0)->getDisplayer()->Update();
+}
+
 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
 {
   int ind = GetProfileSelectionIndex();
index 91f06f88a992df55abb416b54137c246682c482a..7055d77531eef30d4678a4b0b99a676773a365e4 100644 (file)
@@ -72,6 +72,7 @@ protected slots:
   void onProfileIndexChanged();
   void onAddBtnPressed(bool);
   void onRemoveBtnPressed(bool);
+  void onSetColorBtnPressed(bool);
   void onProfileNameChanged(QListWidgetItem* item);
 
 signals:
@@ -91,6 +92,7 @@ private:
   QListWidget*           myProfileNames;
   QPushButton*           myAddProfBtn;
   QPushButton*           myRemProfBtn; 
+  QPushButton*           mySetColorProfBtn;
 public:
   CurveCreator_Widget*   myEditorWidget;
   QGroupBox*             myAddElementBox;
index a7ae37ffb0e6844fe49b7f21c24e654074d6784c..a6398c62b661722e8e2d399b0a10e91dcc234f4a 100644 (file)
@@ -30,6 +30,7 @@
 #include <CurveCreator_Displayer.hxx>
 #include <HYDROData_Entity.h>
 #include <QSet>
+#include <set>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -223,7 +224,8 @@ void HYDROGUI_ProfileOp::startOperation()
     {
       HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
       const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
-      const QColor& CurCol = PColors[i]; 
+      QColor CurCol = PColors[i]; 
+      CP->GetProfileColor(CurCol);
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
@@ -292,6 +294,7 @@ void HYDROGUI_ProfileOp::onAddProfiles()
     for (int i = ExistingProfLen + 1; i <= NewLen; i++)
     {
       Handle(HYDROData_Profile) aCProfile = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); 
+
       QString aProfileName;
       if( !aCProfile.IsNull() )
       {
@@ -313,7 +316,8 @@ void HYDROGUI_ProfileOp::onAddProfiles()
     {
       HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
       const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
-      const QColor& CurCol = PColors[i-ExistingProfLen]; 
+      QColor CurCol = PColors[i-ExistingProfLen]; 
+      CP->GetProfileColor(CurCol);
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
@@ -351,7 +355,8 @@ HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
     SLOT( onRemoveProfile(int) ) );  
   return aDlg;
 }
-#include <set>
+
+
 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
                                        QString& theErrorMsg,
                                        QStringList& theBrowseObjectsEntries )
@@ -397,6 +402,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
     {
       Handle(HYDROData_Profile) HProf = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i));
       int stat = CurveCrProfileToHProfile(myProfiles[i-1], HProf, aProfileNamesFiltered[i-1], true);
+      HProf->SetProfileColor(HYDROData_Tool::toQtColor(myProfiles[i-1]->getColorSection(0)));
       if (stat == 0)
         continue;
       else if (stat == -1)
@@ -412,6 +418,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
   {
     Handle(HYDROData_Profile) aNewProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); 
     int stat = CurveCrProfileToHProfile(myProfiles[0], aNewProfileObj, aProfileNamesFiltered[0], false);
+    aNewProfileObj->SetProfileColor(HYDROData_Tool::toQtColor(myProfiles[0]->getColorSection(0)));
     if (stat == 0)
       return false;
     else if (stat == -1)
@@ -452,7 +459,7 @@ void HYDROGUI_ProfileOp::displayPreviews(const QMap<HYDROGUI_CurveCreatorProfile
         Quantity_Color CurOCCCol = HYDROData_Tool::toOccColor(QCurCol);
         CC->setDisplayer( myDisplayer );
         CC->myPointAspectColor = CurOCCCol;
-        CC->myCurveColor = CurOCCCol;
+        CC->setColorSectionInternal(0, CurOCCCol);
         CC->myLineWidth = 1;
         myDisplayer->display( CC->getAISObject( true ), true );
       }
index a3fa8e5005fd0147291a204cd4e629e0fb7a6d3f..0df5c6caf56ed523a496b128b35497070aac56d1 100644 (file)
@@ -2216,6 +2216,10 @@ Would you like to remove all references from the image?</translation>
       <source>REMOVE_PROFILE</source>
       <translation>Remove Profile</translation>
     </message>
+    <message>
+      <source>SETCOLOR_PROFILE</source>
+      <translation>Set Color</translation>
+    </message>
     <message>
       <source>PROFILE_ALREADY_EXISTS</source>
       <translation>Profile with this name is already exists</translation>