From: enk Date: Wed, 9 Nov 2005 10:11:42 +0000 (+0000) Subject: Improvement: Bug PAL10401 wrong sens in cut line X-Git-Tag: V3_1_0a3~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a7e9d108adf9283e24d85357125a07022f409d3a;p=modules%2Fvisu.git Improvement: Bug PAL10401 wrong sens in cut line --- diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 21103895..3d315c55 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -418,6 +418,9 @@ msgstr "minimal and maximal" #: VisuGUI_CutLinesDlg.cxx +msgid "VisuGUI_CutLinesDlg::LBL_INVERT_CURVES" +msgstr "Invert all curves" + msgid "VisuGUI_CutLinesDlg::LBL_GENERATE_CURVES" msgstr "Generate Curves" diff --git a/src/VISUGUI/VisuGUI_CutLinesDlg.cxx b/src/VISUGUI/VisuGUI_CutLinesDlg.cxx index 2153506b..1db03f8f 100644 --- a/src/VISUGUI/VisuGUI_CutLinesDlg.cxx +++ b/src/VISUGUI/VisuGUI_CutLinesDlg.cxx @@ -17,6 +17,7 @@ #include "VISU_CutLines_i.hh" #include "VISU_PipeLine.hxx" +#include "VISU_PipeLineUtils.hxx" #include "VISU_CutLinesPL.hxx" #include "SVTK_ViewWindow.h" @@ -37,6 +38,10 @@ #include #include #include +#include +#include +#include +#include using namespace std; @@ -46,7 +51,7 @@ bool VisuGUI_CutLinesDlg::MYGenerateCurve = true; VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule) : QDialog(VISU::GetDesktop(theModule), "VisuGUI_CutLinesDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), - myPreviewActor(0) + myPreviewActor(0),myPreviewActorGlyphs(0) { setCaption("Cut Lines Definition"); setSizeGripEnabled(true); @@ -70,6 +75,8 @@ VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule) QRadioButton* aBxy = new QRadioButton( tr( "PARALLEL_XOY" ), mySelPlane); // 0 QRadioButton* aByz = new QRadioButton( tr( "PARALLEL_YOZ" ), mySelPlane); // 1 QRadioButton* aBzx = new QRadioButton( tr( "PARALLEL_ZOX" ), mySelPlane); // 2 + aBxy->setChecked(false); + aByz->setChecked(false); aBzx->setChecked(true); aPlaneLayout->addWidget( mySelPlane ); @@ -107,6 +114,10 @@ VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule) myPreviewCheck->setChecked(false); aPlaneLayout->addWidget(myPreviewCheck); + myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane); + myAllCurvesInvertedCheck->setChecked(false); + aPlaneLayout->addWidget(myAllCurvesInvertedCheck); + myCreateTable = new QCheckBox (tr("LBL_GENERATE_TABLE"), aPlanePane); myCreateTable->setChecked(MYGenerateTable); aPlaneLayout->addWidget( myCreateTable ); @@ -221,6 +232,7 @@ VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg (SalomeApp_Module* theModule) connect(th , SIGNAL(clicked(int)) , this, SLOT(setDefault(int))); connect(myPosSpn2 , SIGNAL(valueChanged(double)) , this, SLOT(DrawTable())); connect(myPreviewCheck, SIGNAL(toggled(bool)) , this, SLOT(onPreviewCheck(bool))); + connect(myAllCurvesInvertedCheck, SIGNAL(toggled(bool)),this, SLOT(onAllCurvesInvertedCheck(bool))); connect(myPosTable , SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int))); connect(myRotXSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double))); connect(myRotYSpn , SIGNAL(valueChanged(double)) , this, SLOT(onRotation(double))); @@ -270,6 +282,8 @@ void VisuGUI_CutLinesDlg::initFromPrsObject (VISU::CutLines_i* thePrs) hasInit = true; myCutLines = new VISU::CutLines_i(thePrs->GetResult(),false); myCutLines->SameAs(thePrs); + myCutLines->CopyCurvesInverted(thePrs->GetCurvesInverted()); + if (myCutLines->IsAllCurvesInverted()) myAllCurvesInvertedCheck->setChecked(true); myBasePlanePos->setText( QString::number(myCutLines->GetBasePlanePosition()) ); myCBSetDef->setChecked(thePrs->IsDefault()); DrawTable(); @@ -305,6 +319,8 @@ int VisuGUI_CutLinesDlg::storeToPrsObject (VISU::CutLines_i* thePrs) thePrs->SetLinePosition( i, myPosTable->text( i, 0 ).toDouble() ); else thePrs->SetDefaultPosition(i); } + if (myAllCurvesInvertedCheck->isChecked()) + thePrs->SetAllCurvesInverted(true); return 1; } @@ -322,12 +338,17 @@ void VisuGUI_CutLinesDlg::createPlanes() vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New(); aPlaneMapper->SetInput(aPolyData->GetOutput()); aPlaneMapper->ScalarVisibilityOff(); - + + myPreviewActorGlyphs = myPreviewActorGlyphs = SALOME_Actor::New(); + myPreviewActorGlyphs->PickableOff(); + updateGlyphs(false); + myPreviewActor = SALOME_Actor::New(); myPreviewActor->PickableOff(); myPreviewActor->SetMapper(aPlaneMapper); aPlaneMapper->Delete(); aView->AddActor(myPreviewActor); + aView->AddActor(myPreviewActorGlyphs); aView->getRenderer()->Render(); aView->onFitAll(); } @@ -336,10 +357,14 @@ void VisuGUI_CutLinesDlg::createPlanes() void VisuGUI_CutLinesDlg::deletePlanes() { if (myPreviewActor == 0) return; - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) + if (SVTK_ViewWindow* aView = VISU::GetViewWindow()){ aView->RemoveActor(myPreviewActor); + aView->RemoveActor(myPreviewActorGlyphs); + } myPreviewActor->Delete(); + myPreviewActorGlyphs->Delete(); myPreviewActor = 0; + myPreviewActorGlyphs = 0; } @@ -389,7 +414,8 @@ void VisuGUI_CutLinesDlg::onCutSelect (int theId, bool theUpdate) myRotXLbl2->setText( tr("LBL_ROT_Z")); myRotYLbl2->setText( tr("LBL_ROT_X")); } - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (theUpdate && myPreviewCheck->isChecked() && (myCutLines != NULL)) { /*myCutLines->SetOrientation2(getOrientaion(false), myRotXSpn2->value()*PI/180., @@ -417,7 +443,8 @@ void VisuGUI_CutLinesDlg::setBaseDefault (bool theUpdate) /* float aPos = myCutLines->GetBasePlanePosition(); myBasePlanePos->setText( QString::number(aPos) ); myBasePlanePos->setEnabled(false);*/ - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (theUpdate && myPreviewCheck->isChecked() && (myCutLines != NULL)) { //myCutLines->SetBasePlanePosition(aPos); // myCutLines->GetPL()->Update(); @@ -488,7 +515,8 @@ void VisuGUI_CutLinesDlg::DrawTable() vh->setLabel( i, str.arg(i+1) ); } // Update preview - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (myPreviewCheck->isChecked()) { // myCutLines->GetPL()->Update(); deletePlanes(); @@ -498,6 +526,78 @@ void VisuGUI_CutLinesDlg::DrawTable() } } +void VisuGUI_CutLinesDlg::updateGlyphs(bool update){ + if (myPreviewActorGlyphs == 0 ) return; + const float *aDirLn = myCutLines->GetCutLinesPL()->GetDirLn(); + const float *aBasePnt = myCutLines->GetCutLinesPL()->GetBasePnt(); + float aSecondPnt[3]; + float aBoundCenter[3]; + + vtkAppendPolyData* aPolyData = myCutLines->GetCutLinesPL()->GetAppendPolyData(); + vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New(); + aPlaneMapper->SetInput(aPolyData->GetOutput()); + float bounds[6]; + aPlaneMapper->GetBounds(bounds); + + for(int i=0; i<3; i++) aBoundCenter[i] = (bounds[i*2] + bounds[i*2+1])/2.0; + for(int i=0; i<3; i++){ + if (myAllCurvesInvertedCheck->isChecked()) + aSecondPnt[i] = aBasePnt[i] + aDirLn[i]; + else + aSecondPnt[i] = -aBasePnt[i] - aDirLn[i]; + } + + float max_bound = 0; + max_bound < bounds[1]-bounds[0] ? max_bound = bounds[1] - bounds[0] : max_bound = max_bound; + max_bound < bounds[3]-bounds[2] ? max_bound = bounds[3] - bounds[2] : max_bound = max_bound; + max_bound < bounds[5]-bounds[4] ? max_bound = bounds[5] - bounds[4] : max_bound = max_bound; + + vtkPolyData* profile = vtkPolyData::New(); + vtkPoints* aPoints = vtkPoints::New(); + vtkGlyph3D* glyphs = vtkGlyph3D::New(); + vtkFloatArray *aFloatArray = vtkFloatArray::New(); + vtkGlyphSource2D* source = vtkGlyphSource2D::New(); + + source->FilledOn(); + source->SetCenter(aBoundCenter); + source->SetGlyphTypeToArrow(); + + aPoints->InsertNextPoint(aBasePnt); + profile->SetPoints(aPoints); + + aFloatArray->SetNumberOfComponents(3); + for(int i=0; i<3 ;i++) + aFloatArray->InsertNextValue(aSecondPnt[i]); + + vtkDataSetAttributes* aDataSetAttributes; + aDataSetAttributes = profile->GetPointData(); + aDataSetAttributes->SetVectors(aFloatArray); + + glyphs->SetScaleFactor(0.25*max_bound); + glyphs->SetVectorModeToUseVector(); + glyphs->SetScaleModeToScaleByVector(); + glyphs->SetInput(profile); + glyphs->SetSource(source->GetOutput()); + + vtkPolyDataMapper* aGlyphsMapper = vtkPolyDataMapper::New(); + aGlyphsMapper->ScalarVisibilityOff(); + aGlyphsMapper->SetInput(glyphs->GetOutput()); + + myPreviewActorGlyphs->SetMapper(aGlyphsMapper); + + profile->Delete(); + glyphs->Delete(); + aPoints->Delete(); + aGlyphsMapper->Delete(); + aFloatArray->Delete(); + source->Delete(); + aPlaneMapper->Delete(); + + if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) + if (update) + vf->Repaint(); +} + //------------------------------------------------------------------------------ void VisuGUI_CutLinesDlg::setDefault (int all) { @@ -584,8 +684,8 @@ void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol) QString aTxt = myPosTable->text(theRow, 0); bool isChanged = !aTxt.isEmpty(); ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged); - - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (myPreviewCheck->isChecked()) { //Update Preview //myCutLines->SetLinePosition( theRow, aTxt.toDouble()); @@ -595,13 +695,13 @@ void VisuGUI_CutLinesDlg::onValueChanged (int theRow, int theCol) //aView->Repaint(); } } - } else { + } else if (theCol == 1){ bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked(); if (isDefault) { //myCutLines->SetDefaultPosition(theRow); // myPosTable->setText(theRow, 0, QString::number(myCutLines->GetLinePosition(theRow))); - - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (myPreviewCheck->isChecked()) { //Update Preview // myCutLines->GetPL()->Update(); @@ -731,10 +831,19 @@ void VisuGUI_CutLinesDlg::onPreviewCheck (bool thePreview) } } +/*! Inverting all curves in the table + */ +void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert) +{ + myCutLines->SetAllCurvesInverted(theInvert); + updateGlyphs(true); +} + void VisuGUI_CutLinesDlg::onRotation (double theValue) { if (myCutLines == NULL) return; - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (myPreviewCheck->isChecked()) { /*myCutLines->SetOrientation(getOrientaion(), @@ -754,7 +863,8 @@ void VisuGUI_CutLinesDlg::onRotation (double theValue) void VisuGUI_CutLinesDlg::onPlanePos (const QString& theValue) { if (myCutLines == NULL) return; - if (SVTK_ViewWindow* aView = VISU::GetViewWindow()) { + SVTK_ViewWindow* aView = VISU::GetViewWindow(); + if (aView) { if (myPreviewCheck->isChecked()) { //myCutLines->SetBasePlanePosition(theValue.toDouble()); // myCutLines->GetPL()->Update(); diff --git a/src/VISUGUI/VisuGUI_CutLinesDlg.h b/src/VISUGUI/VisuGUI_CutLinesDlg.h index 0f225acb..f196660e 100644 --- a/src/VISUGUI/VisuGUI_CutLinesDlg.h +++ b/src/VISUGUI/VisuGUI_CutLinesDlg.h @@ -49,6 +49,7 @@ private slots: void DrawTable(); void onValueChanged (int theRow, int theCol); void onPreviewCheck (bool thePreview); + void onAllCurvesInvertedCheck(bool theInvert); void onRotation (double theValue); void onPlanePos (const QString& theValue); //jfa tmp:void onWindowActivated (SUIT_ViewWindow*); @@ -56,6 +57,7 @@ private slots: private: void createPlanes(); void deletePlanes(); + void updateGlyphs(bool update); QHButtonGroup* mySelPlane; QtxDblSpinBox* myRotXSpn; @@ -88,7 +90,9 @@ private: void setOrientation2 (const VISU::CutPlanes::Orientation orient); SALOME_Actor* myPreviewActor; + SALOME_Actor* myPreviewActorGlyphs; QCheckBox* myPreviewCheck; + QCheckBox* myAllCurvesInvertedCheck; VISU::CutLines_i* myPrs; diff --git a/src/VISU_I/VISU_CutLines_i.cc b/src/VISU_I/VISU_CutLines_i.cc index d542b221..36fd00a5 100644 --- a/src/VISU_I/VISU_CutLines_i.cc +++ b/src/VISU_I/VISU_CutLines_i.cc @@ -83,6 +83,12 @@ void VISU::CutLines_i::SameAs(const CutLines_i* theOrigin){ VISU::ScalarMap_i::SameAs(theOrigin); } +/*! Copy map to /a myMapCurvesInverted. + * \param theCurves - map + */ +void VISU::CutLines_i::CopyCurvesInverted(const TCurvesInv& theCurves){ + myMapCurvesInverted = theCurves; +} VISU::Storable* VISU::CutLines_i::Create(const char* theMeshName, VISU::Entity theEntity, const char* theFieldName, int theIteration) @@ -114,6 +120,20 @@ VISU::Storable* VISU::CutLines_i::Restore(const Storable::TRestoringMap& theMap) if(aCondList[i].toInt() == 0) SetLinePosition(i,aPosList[i].toDouble()); + // Restoring the map - \a myMapCurvesInverted + QStringList aMapCurvesInverted = QStringList::split("|",VISU::Storable::FindValue(theMap,"myMapCurvesInverted") ); + if (aMapCurvesInverted.count() == GetNbLines()){ + for(int i = 0, iEnd = GetNbLines(); i < iEnd ; i++){ + if(aMapCurvesInverted[i].toInt()) + SetCurveInverted(i,true); + else + SetCurveInverted(i,false); + } + } else { + for(int i = 0, iEnd = GetNbLines(); i < iEnd ; i++) + SetCurveInverted(i,false); + } + return ScalarMap_i::Restore(theMap); } @@ -142,6 +162,12 @@ void VISU::CutLines_i::ToStream(std::ostringstream& theStr){ } Storable::DataToStream( theStr, "myLinePosition", aStrPos.latin1()); Storable::DataToStream( theStr, "myLineCondition", aStrCon.latin1()); + + // Storing the map - \a myMapCurvesInverted + QString aStrCurvesInverted; + for(int i = 0, iEnd = GetNbLines(); i < iEnd; i++) + aStrCurvesInverted.append(QString::number(IsCurveInverted(i)) + "|"); + Storable::DataToStream( theStr, "myMapCurvesInverted", aStrCurvesInverted.latin1()); } VISU::CutLines_i::~CutLines_i(){ @@ -232,6 +258,38 @@ CORBA::Boolean VISU::CutLines_i::IsDefaultPosition(CORBA::Long thePlaneNumber){ return myCutLinesPL->IsPartDefault(thePlaneNumber); } +/*! Invert all curves of corresponding table + * see void VISU::CutLines_i::SetCurveInverted(CORBA::Long theCurveNumber,CORBA::Boolean theInvert) + * \param theInvert - Invert all curves, if value is TRUE, else not. + */ +void VISU::CutLines_i::SetAllCurvesInverted(CORBA::Boolean theInvert){ + for (int i=0; iSetNbParts(theNb); @@ -318,6 +376,41 @@ void VISU::CutLines_i::BuildTableOfReal(SALOMEDS::SObject_ptr theSObject){ } if(aXYMapCont.size() == 0) throw std::runtime_error("CutPlanes_i::BuildTableOfReal aXYMapCont.size() == 0 !!!"); + + { + // Invertion all curves in the table, which has inversion flag is TRUE (see \a myMapCurvesInverted) + for(int iLine=0; iLine < iLineEnd; iLine++){ + if (!IsCurveInverted(iLine)) continue; + TXYMap aNewXYMap; + TXYMap& aXYMap = aXYMapCont[iLine]; + TXYMap::const_iterator aXYMapIter = aXYMap.begin(); + std::list XKeys; + for (;aXYMapIter != aXYMap.end() ; aXYMapIter++) XKeys.push_back(aXYMapIter->first); + XKeys.sort(); + if (XKeys.size() > 1) { + float a_first_indx = XKeys.front(); + float a_last_indx = XKeys.back(); + if (a_first_indx > a_last_indx){ + XKeys.reverse(); + float tmp = a_first_indx; + a_first_indx = a_last_indx; + a_last_indx = tmp; + } + std::list::const_iterator aIter = XKeys.begin(); + for (int k=0;k= 0 and aDist<=1.0 + aNewXYMap[1.0 - *aIter] = aXYMap[*aIter]; + } + TXYMap::const_iterator aNewXYMapIter = aNewXYMap.begin(); + aXYMap.clear(); + for (;aNewXYMapIter != aNewXYMap.end();aNewXYMapIter++) { + aXYMap[aNewXYMapIter->first] = aNewXYMapIter->second; + } + } + } + } //Resorting of theXYMap TXYMapCont::iterator aXYMapContIter = aXYMapCont.begin(); for(; aXYMapContIter != aXYMapCont.end(); aXYMapContIter++){ diff --git a/src/VISU_I/VISU_CutLines_i.hh b/src/VISU_I/VISU_CutLines_i.hh index 81ba7ffa..93780198 100644 --- a/src/VISU_I/VISU_CutLines_i.hh +++ b/src/VISU_I/VISU_CutLines_i.hh @@ -82,15 +82,25 @@ namespace VISU{ virtual void SetDefaultPosition(CORBA::Long thePlaneNumber); virtual CORBA::Boolean IsDefaultPosition(CORBA::Long thePlaneNumber); + virtual void SetAllCurvesInverted(CORBA::Boolean theInvert); + virtual CORBA::Boolean IsAllCurvesInverted(); + virtual void SetCurveInverted(CORBA::Long theCurveNumber,CORBA::Boolean theInvert); + virtual CORBA::Boolean IsCurveInverted(CORBA::Long theCurveNumber); + virtual void SetNbLines(CORBA::Long theNb); virtual CORBA::Long GetNbLines(); typedef VISU::CutLines TInterface; VISU_CutLinesPL* GetCutLinesPL(){ return myCutLinesPL;} + + typedef std::map TCurvesInv; + TCurvesInv GetCurvesInverted() {return myMapCurvesInverted;} + void CopyCurvesInverted(const TCurvesInv& theCurves); protected: virtual void DoHook(); VISU_CutLinesPL *myCutLinesPL; + TCurvesInv myMapCurvesInverted; public: static int IsPossible(Result_i* theResult, const char* theMeshName, VISU::Entity theEntity,