From a4ddb8bafa510cc57431846ed83623fdb860c580 Mon Sep 17 00:00:00 2001 From: isn Date: Mon, 24 Sep 2018 17:42:48 +0300 Subject: [PATCH] lots 3,8 Signed-off-by: isn --- src/HYDROData/HYDROData_Entity.cxx | 19 +++++++ src/HYDROData/HYDROData_Entity.h | 8 +++ src/HYDROData/HYDROData_IPolyline.cxx | 55 +++++++++++++++++++ src/HYDROData/HYDROData_IPolyline.h | 10 ++++ src/HYDROData/HYDROData_PolylineXY.cxx | 2 +- src/HYDROData/HYDROData_Profile.cxx | 10 ++++ src/HYDROData/HYDROData_Profile.h | 9 ++- src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx | 20 +++++++ src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h | 6 +- src/HYDROGUI/HYDROGUI_PolylineOp.cxx | 12 +++- src/HYDROGUI/HYDROGUI_ProfileDlg.cxx | 50 ++++++++++++++++- src/HYDROGUI/HYDROGUI_ProfileDlg.h | 2 + src/HYDROGUI/HYDROGUI_ProfileOp.cxx | 15 +++-- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 4 ++ 14 files changed, 210 insertions(+), 12 deletions(-) diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index a39e125b..cef1e985 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -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; diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index bba4f693..f55fa33a 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -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: diff --git a/src/HYDROData/HYDROData_IPolyline.cxx b/src/HYDROData/HYDROData_IPolyline.cxx index a0a2fe30..3bcb60dc 100644 --- a/src/HYDROData/HYDROData_IPolyline.cxx +++ b/src/HYDROData/HYDROData_IPolyline.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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(); + } +} diff --git a/src/HYDROData/HYDROData_IPolyline.h b/src/HYDROData/HYDROData_IPolyline.h index afb307cb..cd306e97 100644 --- a/src/HYDROData/HYDROData_IPolyline.h +++ b/src/HYDROData/HYDROData_IPolyline.h @@ -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: /** diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 17cc1e0b..16e02e74 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -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 ); diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 936e9513..cd8bd084 100644 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -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& theBadProfilesIds, diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index 658bc847..79f24185 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -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) diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx index 2ef728a6..88d6f7c7 100644 --- a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx @@ -20,6 +20,10 @@ #include #include #include +#include +#include +#include +#include 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 ); +}*/ + diff --git a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h index 58fd7152..e45621d6 100644 --- a/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h +++ b/src/HYDROGUI/HYDROGUI_CurveCreatorProfile.h @@ -20,6 +20,7 @@ #define HYDROGUI_CurveCreator_Profile_HeaderFile #include "CurveCreator_Curve.hxx" +#include /** * 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& theConvPoints ); + //virtual void constructAISObject(); + + Quantity_Color myCurveColor; + }; #endif diff --git a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx index a59af02d..cbb18cba 100755 --- a/src/HYDROGUI/HYDROGUI_PolylineOp.cxx +++ b/src/HYDROGUI/HYDROGUI_PolylineOp.cxx @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -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 ); diff --git a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx index 2fb8b2f6..6e8479d1 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileDlg.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -53,6 +54,7 @@ #include #include #include +#include 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(); diff --git a/src/HYDROGUI/HYDROGUI_ProfileDlg.h b/src/HYDROGUI/HYDROGUI_ProfileDlg.h index 91f06f88..7055d775 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileDlg.h +++ b/src/HYDROGUI/HYDROGUI_ProfileDlg.h @@ -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; diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index a7ae37ff..a6398c62 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -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 + + 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 QMapsetDisplayer( myDisplayer ); CC->myPointAspectColor = CurOCCCol; - CC->myCurveColor = CurOCCCol; + CC->setColorSectionInternal(0, CurOCCCol); CC->myLineWidth = 1; myDisplayer->display( CC->getAISObject( true ), true ); } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index a3fa8e50..0df5c6ca 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2216,6 +2216,10 @@ Would you like to remove all references from the image? REMOVE_PROFILE Remove Profile + + SETCOLOR_PROFILE + Set Color + PROFILE_ALREADY_EXISTS Profile with this name is already exists -- 2.30.2