X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FHYDROGUI%2FHYDROGUI_ProfileOp.cxx;h=a7ae37ffb0e6844fe49b7f21c24e654074d6784c;hb=b8b330bd3b77a53aa65978028660880d7b32412f;hp=1c9c96adc5250777ac1b512cebebcba2e5ef3f07;hpb=d73a62c7e1e6715fec59c1dfca7828047279ba9e;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx index 1c9c96ad..a7ae37ff 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileOp.cxx @@ -26,7 +26,10 @@ #include #include #include +#include #include +#include +#include #include #include @@ -35,15 +38,97 @@ #include #include #include - +#include +#include #include #include //static int ZValueIncrement = 0; +static void ProfileUZToCurveCrProfile(const Handle(HYDROData_ProfileUZ)& aProfileUZ, + HYDROGUI_CurveCreatorProfile* outProfile) +{ + CurveCreator::Coordinates aCurveCoords; + CurveCreator::SectionsMap aSectionsMap; + + HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints(); + CurveCreator::PosPointsList aPoints; + for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) + { + const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k ); + aCurveCoords.clear(); + aCurveCoords.push_back( aSectPoint.X() ); + aCurveCoords.push_back( aSectPoint.Y() ); + + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords ); + aPoints.push_back( aPosPoint ); + } + + aSectionsMap[0] = aPoints; + outProfile->addPointsInternal( aSectionsMap ); + + HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 ); + + CurveCreator::SectionType aCurveType = CurveCreator::Polyline; + if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE ) + aCurveType = CurveCreator::Spline; + + outProfile->setSectionType( 0, aCurveType ); +} + +static int CurveCrProfileToHProfile(const HYDROGUI_CurveCreatorProfile* outProfile, + Handle(HYDROData_Profile) theProfileObj, + const QString theProfileName, + bool IsEdit) +{ + if( theProfileObj.IsNull() ) + return 0; + + Handle(HYDROData_ProfileUZ) aProfileUZ = theProfileObj->GetProfileUZ(); + if ( aProfileUZ.IsNull() ) + return 0; + + theProfileObj->SetName(theProfileName); + + HYDROData_ProfileUZ::PointsList aProfileParamPoints; + + Handle(TColgp_HArray1OfPnt) aCurveCoords = outProfile->GetDifferentPoints( 0 ); + if ( aCurveCoords.IsNull() || aCurveCoords->Size() <= 2 ) + return -1; + + for ( int k = aCurveCoords->Lower(); k <= aCurveCoords->Upper() ; k++ ) + { + HYDROData_ProfileUZ::Point aProfileParamPoint; + + aProfileParamPoint.SetX( aCurveCoords->Value( k ).X() ); + aProfileParamPoint.SetY( aCurveCoords->Value( k ).Y() ); + + aProfileParamPoints.Append( aProfileParamPoint ); + } + theProfileObj->SetParametricPoints( aProfileParamPoints ); + + HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE; + if ( outProfile->getSectionType( 0 ) == CurveCreator::Spline ) + aSectType = HYDROData_ProfileUZ::SECTION_SPLINE; + + aProfileUZ->SetSectionType( 0, aSectType ); + + if ( !IsEdit ) + theProfileObj->SetBorderColor( theProfileObj->DefaultBorderColor() ); + + // At first we update the child u,z profile object + aProfileUZ->Changed( HYDROData_Entity::Geom_2d ); + aProfileUZ->Update(); + + // And now we update our edited object + theProfileObj->Update(); + return 1; +} + HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit ) -: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL) +: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), + myDisplayer (NULL) { setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) ); } @@ -65,6 +150,7 @@ void HYDROGUI_ProfileOp::deleteSelected() /** * Checks whether there are some to delete */ +#include bool HYDROGUI_ProfileOp::deleteEnabled() { HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel(); @@ -73,66 +159,171 @@ bool HYDROGUI_ProfileOp::deleteEnabled() void HYDROGUI_ProfileOp::startOperation() { - if( myProfile ) - delete myProfile; + if (!myProfiles.empty()) + { + for (int i = 0; i < myProfiles.size(); i++) + { + delete myProfiles[i]; + myProfiles[i] = NULL; + } + myProfiles.clear(); + } + + if (!myIsEdit) + myEditedObjects.Clear(); + + if (myCurveToProfile.IsEmpty()) + myCurveToProfile.Clear(); + + if( myIsEdit && isApplyAndClose() ) + myEditedObjects = HYDROGUI_Tool::GetSelectedObjects(module()); - myProfile = new HYDROGUI_CurveCreatorProfile(); + int lenP = myEditedObjects.Length(); + myProfiles.resize(lenP == 0 ? 1 : myEditedObjects.Length()); + for (int i = 0; i < myProfiles.size(); i++) + myProfiles[i] = new HYDROGUI_CurveCreatorProfile(); + //mySingleProfileMode = myEditedObjects.IsEmpty(); HYDROGUI_Operation::startOperation(); HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel(); + aPanel->myEditorWidget->setCurve(NULL); aPanel->reset(); setPreviewManager( aPanel->viewManager() ); setCursor(); - if( myIsEdit ) - if ( isApplyAndClose() ) - myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ); - - QString aProfileName; - if( !myEditedObject.IsNull() ) + //aPanel->SetSingleProfileMode(mySingleProfileMode); + QMap CurveToColor; + if( lenP ) { - Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false ); - if ( !aProfileUZ.IsNull() ) + for (int i = 1; i <= lenP; i++) { - CurveCreator::Coordinates aCurveCoords; - CurveCreator::SectionsMap aSectionsMap; - - HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints(); - CurveCreator::PosPointsList aPoints; - for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k ) + Handle(HYDROData_Profile) aCProfile = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); + QString aProfileName; + if( !aCProfile.IsNull() ) { - const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k ); - aCurveCoords.clear(); - aCurveCoords.push_back( aSectPoint.X() ); - aCurveCoords.push_back( aSectPoint.Y() ); - - CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords ); - aPoints.push_back( aPosPoint ); + Handle(HYDROData_ProfileUZ) aProfileUZ = aCProfile->GetProfileUZ( false ); + if ( !aProfileUZ.IsNull() ) + { + HYDROGUI_CurveCreatorProfile* CP = new HYDROGUI_CurveCreatorProfile(); + myProfiles[i-1] = CP; + ProfileUZToCurveCrProfile(aProfileUZ, CP); + myCurveToProfile.Bind(CP, aCProfile); + } } + } + int ext = myCurveToProfile.Extent(); //ext should be equal to lenP + QVector PColors; + if (myIsEdit) + HYDROData_Tool::GenerateRepeatableRandColors(ext, PColors); + else + PColors << QColor(0,0,255); //default color + + for (int i = 0; i < myProfiles.size(); i++) + { + HYDROGUI_CurveCreatorProfile* CC = myProfiles[i]; + const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC); + const QColor& CurCol = PColors[i]; + CurveToColor[CC] = CurCol; + const QString& profName = CP->GetName(); + const QColor& PColor = CurCol; + if (myIsEdit) + aPanel->addProfileName(profName, PColor); + else + aPanel->setProfileName(profName); + } + } + + if (!myIsEdit) + { + QString aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) ); + aPanel->setProfileName( aProfileName ); + } - aSectionsMap[0] = aPoints; - myProfile->addPointsInternal( aSectionsMap ); + if (!myProfiles.empty()) + { + aPanel->setProfile( myProfiles[0] ); + aPanel->setProfilesPointer( &myProfiles ); + } + displayPreviews(CurveToColor, 0, myProfiles.size(), true, true ); +} - HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 ); +void HYDROGUI_ProfileOp::onAddProfiles() +{ + if( !myIsEdit ) + return; - CurveCreator::SectionType aCurveType = CurveCreator::Polyline; - if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE ) - aCurveType = CurveCreator::Spline; + QSet edObjNamesMap; + for (int i = 1; i <= myEditedObjects.Length(); i++) + edObjNamesMap.insert( myEditedObjects(i)->GetName()); - myProfile->setSectionType( 0, aCurveType ); - } + HYDROData_SequenceOfObjects aSelectedObj = HYDROGUI_Tool::GetSelectedObjects( module() );; + int ExistingProfLen = myEditedObjects.Length(); + for (int i = 1; i <= aSelectedObj.Length(); i++) + { + Handle(HYDROData_Entity) CurProf = Handle(HYDROData_Entity)::DownCast(aSelectedObj(i)); + if (CurProf.IsNull()) + continue; + if (!edObjNamesMap.contains(CurProf->GetName())) + myEditedObjects.Append(CurProf); + } - aProfileName = myEditedObject->GetName(); + int NewLen = myEditedObjects.Length(); + bool IsNewPoly = NewLen - ExistingProfLen; + if (aSelectedObj.IsEmpty()) + { + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "PROFILEOP_WARNING" ), tr ("PROFILES_ARE_NOT_SELECTED") ); + return; } - else + if (!IsNewPoly) { - aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) ); + SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "PROFILEOP_WARNING" ), tr ("PROFILES_ALREADY_PRESENT") ); + return; } + myProfiles.resize(myEditedObjects.Length()); + for (int i = myProfiles.size() - 1; i < myEditedObjects.Length(); i++) + myProfiles[i] = new HYDROGUI_CurveCreatorProfile(); + + HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel(); + QMap CurveToColor; + if( IsNewPoly ) + { + //TODO move to ext func! + for (int i = ExistingProfLen + 1; i <= NewLen; i++) + { + Handle(HYDROData_Profile) aCProfile = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); + QString aProfileName; + if( !aCProfile.IsNull() ) + { + Handle(HYDROData_ProfileUZ) aProfileUZ = aCProfile->GetProfileUZ( false ); + if ( !aProfileUZ.IsNull() ) + { + HYDROGUI_CurveCreatorProfile* CP = new HYDROGUI_CurveCreatorProfile(); + myProfiles[i-1] = CP; + ProfileUZToCurveCrProfile(aProfileUZ, CP); + myCurveToProfile.Bind(CP, aCProfile); + } + } + } + //int ext = myCurveToProfile.Extent(); //ext should be equal to lenP + QVector PColors; + HYDROData_Tool::GenerateRepeatableRandColors(NewLen - ExistingProfLen, PColors); - aPanel->setProfileName( aProfileName ); - aPanel->setProfile( myProfile ); - displayPreview(); + for (int i = ExistingProfLen; i < NewLen; i++) + { + HYDROGUI_CurveCreatorProfile* CC = myProfiles[i]; + const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC); + const QColor& CurCol = PColors[i-ExistingProfLen]; + CurveToColor[CC] = CurCol; + const QString& profName = CP->GetName(); + const QColor& PColor = CurCol; + if (myIsEdit) + aPanel->addProfileName(profName, PColor); + else + aPanel->setProfileName(profName); + } + } + displayPreviews(CurveToColor, ExistingProfLen, NewLen, false, false); } void HYDROGUI_ProfileOp::abortOperation() @@ -153,10 +344,14 @@ void HYDROGUI_ProfileOp::commitOperation() HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const { - HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() ); + HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName(), myIsEdit ); + connect( aDlg, SIGNAL( AddProfiles() ), this, + SLOT( onAddProfiles() ) ); + connect( aDlg, SIGNAL( RemoveProfile(int) ), this, + SLOT( onRemoveProfile(int) ) ); return aDlg; } - +#include bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags, QString& theErrorMsg, QStringList& theBrowseObjectsEntries ) @@ -165,94 +360,75 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags, if ( !aPanel ) return false; - QString aProfileName = aPanel->getProfileName().simplified(); - if ( aProfileName.isEmpty() ) + QStringList aProfileNames = aPanel->getProfileNames(); + QVector aProfileNamesFiltered; + int i = 0; + // QSet edObjStrMap = aProfileNames.toSet(); + QSet ObjStrMapNE ; + HYDROData_SequenceOfObjects allobj = doc()->CollectAllObjects(); + for (int i=1;i<=allobj.Size();i++ ) + ObjStrMapNE.insert(allobj(i)->GetName()); + for (int i=1; i<=myEditedObjects.Size();i++) + ObjStrMapNE.remove(myEditedObjects(i)->GetName()); + bool warn = false; + QString title = tr( "PROFILEOP_WARNING" ); + QString mes = tr("PROFILE_RENAMING_NOTIF") + "\n"; + foreach (QString profName, aProfileNames) { - theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); - return false; - } - - if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) ) - { - // check that there are no other objects with the same name in the document - Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName ); - if( !anObject.IsNull() ) + i++; + if( !myIsEdit || ObjStrMapNE.contains(profName) || profName.isEmpty() ) { - theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName ); - return false; + QString newName = HYDROData_Tool::GenerateObjectName(doc(), "Profile"); + mes += profName + " => " + newName + "\n"; + profName = newName; + warn = true; } + aProfileNamesFiltered.append(profName); } - - Handle(HYDROData_Profile) aProfileObj; - if( myIsEdit ){ - aProfileObj = myEditedObject; - } - else{ - aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); - } - - if( aProfileObj.IsNull() ) - return false; - - Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ(); - if ( aProfileUZ.IsNull() ) - return false; - - aProfileObj->SetName(aProfileName); - - HYDROData_ProfileUZ::PointsList aProfileParamPoints; - - CurveCreator::Coordinates aCurveCoords = myProfile->getCoords( 0 ); - if ( aCurveCoords.size() <= 2 ) - { - theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); - return false; - } - - for ( int k = 0 ; k + 1 < aCurveCoords.size() ; k++ ) - { - HYDROData_ProfileUZ::Point aProfileParamPoint; - - aProfileParamPoint.SetX( aCurveCoords.at( k ) ); - k++; - aProfileParamPoint.SetY( aCurveCoords.at( k ) ); - - aProfileParamPoints.Append( aProfileParamPoint ); - } - aProfileObj->SetParametricPoints( aProfileParamPoints ); - - HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE; - if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline ) - aSectType = HYDROData_ProfileUZ::SECTION_SPLINE; - - aProfileUZ->SetSectionType( 0, aSectType ); - - if ( !myIsEdit ) - { - aProfileObj->SetBorderColor( aProfileObj->DefaultBorderColor() ); - } - - // At first we update the child u,z profile object - aProfileUZ->Changed( HYDROData_Entity::Geom_2d ); - aProfileUZ->Update(); - - // And now we update our edited object - aProfileObj->Update(); - module()->setIsToUpdate( aProfileObj ); - + if (myIsEdit && warn) +#ifndef TEST_MODE + SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes ); +#endif + // theUpdateFlags = UF_Model; - if ( myIsEdit ) + if (myIsEdit) + { + for (int i = 1; i <= myEditedObjects.Size(); i++) + { + Handle(HYDROData_Profile) HProf = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); + int stat = CurveCrProfileToHProfile(myProfiles[i-1], HProf, aProfileNamesFiltered[i-1], true); + if (stat == 0) + continue; + else if (stat == -1) + { + theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); //TODO resolve this + continue; + } + module()->setIsToUpdate( HProf ); + } theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer; + } else { - QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj ); + Handle(HYDROData_Profile) aNewProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); + int stat = CurveCrProfileToHProfile(myProfiles[0], aNewProfileObj, aProfileNamesFiltered[0], false); + if (stat == 0) + return false; + else if (stat == -1) + { + theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); + return false; + } + module()->setIsToUpdate( aNewProfileObj ); + QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aNewProfileObj ); theBrowseObjectsEntries.append( anEntry ); } return true; } -void HYDROGUI_ProfileOp::displayPreview() +void HYDROGUI_ProfileOp::displayPreviews(const QMap& CurveToColor, + int firstIndProf, int lastIndProf, bool createNewDisplayer, bool SwitchToFirstProf) { HYDROGUI_ProfileDlg* aPanel = dynamic_cast( inputPanel() ); if( aPanel ) @@ -260,25 +436,77 @@ void HYDROGUI_ProfileOp::displayPreview() Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext(); if( !aCtx.IsNull() ) { - CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx ); - myProfile->setDisplayer( aDisplayer ); - aDisplayer->display( myProfile->getAISObject( true ), true ); + if (myDisplayer) + { + //delete myDisplayer; + //myDisplayer = NULL; + } + if (createNewDisplayer) + myDisplayer = new CurveCreator_Displayer( aCtx ); + for (int i = firstIndProf; i < lastIndProf; i++ ) + { + HYDROGUI_CurveCreatorProfile* CC = myProfiles[i]; + QColor QCurCol = QColor(0,0,255); //def color + if (myIsEdit) + QCurCol = CurveToColor[CC]; + Quantity_Color CurOCCCol = HYDROData_Tool::toOccColor(QCurCol); + CC->setDisplayer( myDisplayer ); + CC->myPointAspectColor = CurOCCCol; + CC->myCurveColor = CurOCCCol; + CC->myLineWidth = 1; + myDisplayer->display( CC->getAISObject( true ), true ); + } } + if (SwitchToFirstProf && myProfiles.size() > 1) + aPanel->switchToFirstProfile(); } } void HYDROGUI_ProfileOp::erasePreview() { HYDROGUI_ProfileDlg* aPanel = dynamic_cast( inputPanel() ); - CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0; - if( aPanel && aDisplayer ) + //CurveCreator_Displayer* aDisplayer = myProfiles[0] ? myProfile[0]->getDisplayer() : 0; + if( aPanel && myDisplayer ) { Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext(); if( !aCtx.IsNull() ) { - aDisplayer->eraseAll( true ); + myDisplayer->eraseAll( true ); } } + myCurveToProfile.Clear(); +} + +void HYDROGUI_ProfileOp::onRemoveProfile(int index) +{ + if (index >= myProfiles.size() ) + return; + + if (!myIsEdit) + return; + + HYDROGUI_CurveCreatorProfile* CP = myProfiles[index]; + myProfiles.erase (myProfiles.begin()+index); + myEditedObjects.Remove(index+1); + myCurveToProfile.UnBind(CP); + + HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel(); + //aPanel->reset(); + //setPreviewManager( aPanel->viewManager() ); + //setCursor(); + + aPanel->BlockProfileNameSignals(true); + aPanel->eraseProfile(index); + + Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext(); + if( !aCtx.IsNull() && myDisplayer) + myDisplayer->erase( CP->getAISObject(false), true); + CP->SetEraseAllState(false); + delete CP; + int selectedInd = aPanel->GetProfileSelectionIndex(); + if (selectedInd > -1) + aPanel->SwitchToProfile(selectedInd); + aPanel->BlockProfileNameSignals(false); } bool HYDROGUI_ProfileOp::isValid( SUIT_Operation* theOtherOp ) const