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"
26 #include "CurveCreator.hxx"
27 #include "CurveCreator_Curve.hxx"
28 #include "CurveCreator_CurveEditor.hxx"
29 #include "HYDROGUI_AISCurve.h"
31 #include <HYDROData_Document.h>
32 #include <HYDROData_Polyline.h>
33 #include <CurveCreator_Curve.hxx>
34 #include <CurveCreator_CurveEditor.hxx>
36 #include <LightApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <LightApp_UpdateFlags.h>
40 #include <OCCViewer_ViewManager.h>
41 #include <OCCViewer_ViewModel.h>
43 #include <OCCViewer_AISSelector.h>
45 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
46 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL),
47 myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL)
49 setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
52 HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
56 HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
58 HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() );
59 connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
63 bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
64 QString& theErrorMsg )
66 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
68 int aStudyId = module()->getStudyId();
69 bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
70 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
71 if( aDocument.IsNull() )
74 Handle(HYDROData_Polyline) aPolylineObj;
76 aPolylineObj = myEditedObject;
79 aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
82 if( aPolylineObj.IsNull() )
85 QString aPolylineName = aPanel->getPolylineName();
86 aPolylineObj->SetName(aPolylineName);
88 if( myCurve->getDimension() == CurveCreator::Dim2d )
90 aPolylineObj->setDimension(aDimInt);
91 QList<PolylineSection> aPolylineData;
92 for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
93 PolylineSection aSect;
94 aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
95 aSect.myIsClosed = myCurve->isClosed(i);
96 aSect.myType = PolylineSection::SECTION_POLYLINE;
97 if( myCurve->getType(i) == CurveCreator::BSpline ){
98 aSect.myType = PolylineSection::SECTION_SPLINE;
100 CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
101 for( int j = 0 ; j < aCoords.size() ; j++ ){
102 aSect.myCoords << aCoords.at(j);
104 aPolylineData << aSect;
106 aPolylineObj->setPolylineData(aPolylineData);
108 theUpdateFlags = UF_Model;
109 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true );
113 void HYDROGUI_PolylineOp::onCreatePreview()
115 LightApp_Application* anApp = module()->getApp();
117 myActiveViewManager = anApp->activeViewManager();
119 myPreviewViewManager =
120 dynamic_cast<OCCViewer_ViewManager*>( anApp->createViewManager( OCCViewer_Viewer::Type() ) );
121 if( myPreviewViewManager )
123 anApp->selectionMgr()->setEnabled(false);
124 myPreviewViewManager->setTitle( tr( "CREATE_CURVE" ) );
125 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
126 aViewer->enableSelection(true);
127 aViewer->enableMultiselection(true);
128 Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext();
130 myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx);
132 myAISCurve->Display();
136 void HYDROGUI_PolylineOp::startOperation()
138 CurveCreator_Curve* anOldCurve = myCurve;
140 HYDROGUI_Operation::startOperation();
142 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
145 myEditedObject = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
146 if( !myEditedObject.IsNull() )
148 int anIntDim = myEditedObject->getDimension();
149 CurveCreator::Dimension aDim = CurveCreator::Dim3d;
151 aDim = CurveCreator::Dim2d;
152 myCurve = new CurveCreator_Curve(aDim);
153 QList<PolylineSection> aPolylineData = myEditedObject->getPolylineData();
155 CurveCreator_CurveEditor* anEdit = new CurveCreator_CurveEditor(myCurve);
156 for( int i = 0 ; i < aPolylineData.size() ; i++ ){
157 std::string aName = HYDROGUI_Tool::ToQString(aPolylineData[i].mySectionName).toStdString();
158 bool isClosed = aPolylineData[i].myIsClosed;
159 CurveCreator::Type aType = CurveCreator::Polyline;
160 if( aPolylineData[i].myType == PolylineSection::SECTION_SPLINE ){
161 aType = CurveCreator::BSpline;
163 CurveCreator::Coordinates aCoords;
164 for( int j = 0 ; j < aPolylineData[i].myCoords.size() ; j++ ){
165 aCoords.push_back(aPolylineData[i].myCoords[j]);
167 anEdit->addSection( aName, aType, isClosed, aCoords );
170 aPanel->setPolylineName( myEditedObject->GetName() );
174 myCurve = new CurveCreator_Curve(CurveCreator::Dim3d);
175 aPanel->setCurve(myCurve);
176 QString aNewName = HYDROGUI_Tool::GenerateObjectName( module(), tr("POLYLINE_PREFIX") );
177 aPanel->setPolylineName(aNewName);
179 aPanel->setCurve(myCurve);
181 myAISCurve->setCurve(myCurve);
187 void HYDROGUI_PolylineOp::onEditorSelectionChanged()
189 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
196 QList<int> aSelSections = aPanel->getSelectedSections();
197 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
199 if( aSelSections.contains(i) ){
200 myAISCurve->highlightSection(i, aIsHl);