#include <vtkPolyData.h>
#include <vtkAppendPolyData.h>
#include <vtkDataSetMapper.h>
+#include <vtkGlyph3D.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkFloatArray.h>
+#include <vtkGlyphSource2D.h>
+#include <vtkPointData.h>
+#include <vtkDataSetAttributes.h>
using namespace std;
VisuGUI_CutLinesDlg::VisuGUI_CutLinesDlg(bool theIsCreation)
: QDialog( QAD_Application::getDesktop(), "VisuGUI_CutLinesDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
- myPreviewActor(0),
+ myPreviewActor(0),myPreviewActorGlyphs(0),
myStudy(QAD_Application::getDesktop()->getActiveStudy())
{
myStudyFrame = myStudy -> getActiveStudyFrame();
QRadioButton* aBxy = new QRadioButton( tr( "|| X-Y" ), mySelPlane); // 0
QRadioButton* aByz = new QRadioButton( tr( "|| Y-Z" ), mySelPlane); // 1
QRadioButton* aBzx = new QRadioButton( tr( "|| Z-X" ), mySelPlane); // 2
+ aBxy->setChecked(false);
+ aByz->setChecked(false);
aBzx->setChecked(true);
aPlaneLayout->addWidget( mySelPlane );
aPlaneLayout->addStretch();
+ myAllCurvesInvertedCheck = new QCheckBox(tr("LBL_INVERT_CURVES"), aPlanePane);
+ myAllCurvesInvertedCheck->setChecked(false);
+ aPlaneLayout->addWidget(myAllCurvesInvertedCheck);
aTabPane->addTab( aPlanePane, tr("LBL_LINES_PLANE") );
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 ) ) );
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();
thePrs->SetLinePosition( i, myPosTable->text( i, 0 ).toDouble() );
else thePrs->SetDefaultPosition(i);
}
+ if (myAllCurvesInvertedCheck->isChecked())
+ thePrs->SetAllCurvesInverted(true);
return 1;
}
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();
GET_VTK_VIEWFRAME(myStudy)->AddActor(myPreviewActor);
+ GET_VTK_VIEWFRAME(myStudy)->AddActor(myPreviewActorGlyphs);
}
//------------------------------------------------------------------------------
void VisuGUI_CutLinesDlg::deletePlanes() {
if (myPreviewActor == 0) return;
- if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
+ if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)){
vf->RemoveActor(myPreviewActor);
+ vf->RemoveActor(myPreviewActorGlyphs);
+ }
myPreviewActor->Delete();
myPreviewActor = 0;
+ myPreviewActorGlyphs->Delete();
+ myPreviewActorGlyphs = 0;
}
}
}
+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 (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
+ if (myPreviewCheck->isChecked())
+ vf->Repaint();
+}
+
//------------------------------------------------------------------------------
void VisuGUI_CutLinesDlg::setDefault(int all)
{
}
}
+/*! Inverting all curves in the table
+ */
+void VisuGUI_CutLinesDlg::onAllCurvesInvertedCheck(bool theInvert)
+{
+ if (myAllCurvesInvertedCheck->isChecked()){
+ myCutLines->SetAllCurvesInverted(true);
+ myPrs->SetAllCurvesInverted(true);
+ }
+ else {
+ myCutLines->SetAllCurvesInverted(false);
+ myPrs->SetAllCurvesInverted(false);
+ }
+ updateGlyphs(true);
+}
+
void VisuGUI_CutLinesDlg::onRotation(double theValue) {
if (myCutLines == NULL) return;
if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
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)
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);
}
}
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(){
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; i<GetNbLines(); i++) SetCurveInverted(i,theInvert);
+}
+
+/*! Checks the orientation of all curves
+ * \retval TRUE - if all curves are inverted, else FALSE
+ */
+CORBA::Boolean VISU::CutLines_i::IsAllCurvesInverted(){
+ for (int i=0; i<GetNbLines(); i++)
+ if (!IsCurveInverted(i)) return false;
+ return true;
+}
+
+/*! Sets orientation of curve
+ * \param theCurveNumber - integer value, number of cut line.
+ * \param theInvert - boolean value, TRUE or false.
+ */
+void VISU::CutLines_i::SetCurveInverted(CORBA::Long theCurveNumber,CORBA::Boolean theInvert){
+ myMapCurvesInverted[theCurveNumber] = theInvert;
+}
+
+/*! Checks orientation of curve.
+ * \param theCurveNumber - integer value, number of cut line.
+ * \retval TRUE - if line in the table is inverted, else FALSE.
+ */
+CORBA::Boolean VISU::CutLines_i::IsCurveInverted(CORBA::Long theCurveNumber){
+ return myMapCurvesInverted[theCurveNumber];
+}
void VISU::CutLines_i::SetNbLines(CORBA::Long theNb) {
myCutLinesPL->SetNbParts(theNb);
}
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<float> 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<float>::const_iterator aIter = XKeys.begin();
+ for (int k=0;k<XKeys.size() and aIter != XKeys.end();k++,aIter++){
+ // Warning: value '1.0' come from workaround:
+ // see also aDist = vtkMath::Dot(aVect,aDirLn) / aBoundPrjLn[2];
+ // aDist >= 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++){