1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_PolylineOp.h"
24 #include "HYDROGUI_PolylineDlg.h"
25 #include "HYDROGUI_Tool.h"
27 #include <HYDROData_Document.h>
28 #include <HYDROData_Polyline.h>
29 #include <CurveCreator_Curve.hxx>
30 #include <CurveCreator_CurveEditor.hxx>
32 #include <LightApp_Application.h>
33 #include <LightApp_UpdateFlags.h>
36 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
37 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL)
39 setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
42 HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
46 HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
48 return new HYDROGUI_PolylineDlg( module(), getName() );
51 bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
52 QString& theErrorMsg )
54 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
56 int aStudyId = module()->getStudyId();
57 bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
58 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
59 if( aDocument.IsNull() )
62 Handle(HYDROData_Polyline) aPolylineObj;
64 aPolylineObj = myEditedObject;
67 aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
70 if( aPolylineObj.IsNull() )
73 QString aPolylineName = aPanel->getPolylineName();
74 aPolylineObj->SetName(aPolylineName);
76 if( myCurve->getDimension() == CurveCreator::Dim2d )
78 aPolylineObj->setDimension(aDimInt);
79 QList<PolylineSection> aPolylineData;
80 for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
81 PolylineSection aSect;
82 aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
83 aSect.myIsClosed = myCurve->isClosed(i);
84 aSect.myType = PolylineSection::SECTION_POLYLINE;
85 if( myCurve->getType(i) == CurveCreator::BSpline ){
86 aSect.myType = PolylineSection::SECTION_SPLINE;
88 CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
89 for( int j = 0 ; j < aCoords.size() ; j++ ){
90 aSect.myCoords << aCoords.at(j);
92 aPolylineData << aSect;
94 aPolylineObj->setPolylineData(aPolylineData);
96 theUpdateFlags = UF_Model;
97 aPolylineObj->SetVisibility( true );
101 void HYDROGUI_PolylineOp::startOperation()
103 CurveCreator_Curve* anOldCurve = myCurve;
105 HYDROGUI_Operation::startOperation();
107 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
110 myEditedObject = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
111 if( !myEditedObject.IsNull() )
113 int anIntDim = myEditedObject->getDimension();
114 CurveCreator::Dimension aDim = CurveCreator::Dim3d;
116 aDim = CurveCreator::Dim2d;
117 myCurve = new CurveCreator_Curve(aDim);
118 QList<PolylineSection> aPolylineData = myEditedObject->getPolylineData();
120 CurveCreator_CurveEditor* anEdit = new CurveCreator_CurveEditor(myCurve);
121 for( int i = 0 ; i < aPolylineData.size() ; i++ ){
122 std::string aName = HYDROGUI_Tool::ToQString(aPolylineData[i].mySectionName).toStdString();
123 bool isClosed = aPolylineData[i].myIsClosed;
124 CurveCreator::Type aType = CurveCreator::Polyline;
125 if( aPolylineData[i].myType == PolylineSection::SECTION_SPLINE ){
126 aType = CurveCreator::BSpline;
128 CurveCreator::Coordinates aCoords;
129 for( int j = 0 ; j < aPolylineData[i].myCoords.size() ; j++ ){
130 aCoords.push_back(aPolylineData[i].myCoords[j]);
132 anEdit->addSection( aName, aType, isClosed, aCoords );
135 aPanel->setPolylineName( myEditedObject->GetName() );
139 myCurve = new CurveCreator_Curve(CurveCreator::Dim3d);
140 aPanel->setCurve(myCurve);
141 QString aNewName = HYDROGUI_Tool::GenerateObjectName( module(), tr("POLYLINE_PREFIX") );
142 aPanel->setPolylineName(aNewName);
144 aPanel->setCurve(myCurve);