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>
42 #include <OCCViewer_ViewWindow.h>
44 #include <OCCViewer_AISSelector.h>
46 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
47 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myCurve(NULL),
48 myActiveViewManager(NULL), myPreviewViewManager(NULL), myAISCurve(NULL)
50 setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
53 HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
57 HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
59 HYDROGUI_PolylineDlg* aDlg = new HYDROGUI_PolylineDlg( module(), getName() );
60 connect( aDlg ,SIGNAL( selectionChanged() ), this, SLOT( onEditorSelectionChanged() ) );
64 bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags,
65 QString& theErrorMsg )
67 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
69 int aStudyId = module()->getStudyId();
70 bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
71 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
72 if( aDocument.IsNull() )
75 Handle(HYDROData_Polyline) aPolylineObj;
77 aPolylineObj = myEditedObject;
80 aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
83 if( aPolylineObj.IsNull() )
86 QString aPolylineName = aPanel->getPolylineName();
87 aPolylineObj->SetName(aPolylineName);
89 if( myCurve->getDimension() == CurveCreator::Dim2d )
91 aPolylineObj->setDimension(aDimInt);
92 QList<PolylineSection> aPolylineData;
93 for( int i=0 ; i < myCurve->getNbSections() ; i++ ){
94 PolylineSection aSect;
95 aSect.mySectionName = HYDROGUI_Tool::ToExtString( QString::fromLocal8Bit(myCurve->getSectionName(i).c_str()));
96 aSect.myIsClosed = myCurve->isClosed(i);
97 aSect.myType = PolylineSection::SECTION_POLYLINE;
98 if( myCurve->getType(i) == CurveCreator::BSpline ){
99 aSect.myType = PolylineSection::SECTION_SPLINE;
101 CurveCreator::Coordinates aCoords = myCurve->getPoints(i);
102 for( int j = 0 ; j < aCoords.size() ; j++ ){
103 aSect.myCoords << aCoords.at(j);
105 aPolylineData << aSect;
107 aPolylineObj->setPolylineData(aPolylineData);
109 theUpdateFlags = UF_Model;
110 module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), aPolylineObj, true );
114 void HYDROGUI_PolylineOp::onCreatePreview()
116 LightApp_Application* anApp = module()->getApp();
118 myActiveViewManager = anApp->activeViewManager();
120 myPreviewViewManager =
121 dynamic_cast<OCCViewer_ViewManager*>( anApp->createViewManager( OCCViewer_Viewer::Type() ) );
122 if( myPreviewViewManager )
124 //anApp->selectionMgr()->setEnabled(false); // what the hell?!
125 myPreviewViewManager->setTitle( tr( "CREATE_POLYLINE" ) );
126 OCCViewer_Viewer* aViewer = myPreviewViewManager->getOCCViewer();
127 aViewer->enableSelection(true);
128 aViewer->enableMultiselection(true);
129 Handle_AIS_InteractiveContext aCtx = aViewer->getAISContext();
131 OCCViewer_ViewWindow* vw = (OCCViewer_ViewWindow*)myPreviewViewManager->getActiveView();
134 myAISCurve = new HYDROGUI_AISCurve(myCurve, aCtx);
136 myAISCurve->Display();
140 void HYDROGUI_PolylineOp::startOperation()
142 CurveCreator_Curve* anOldCurve = myCurve;
144 HYDROGUI_Operation::startOperation();
146 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
149 myEditedObject = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
150 if( !myEditedObject.IsNull() )
152 int anIntDim = myEditedObject->getDimension();
153 CurveCreator::Dimension aDim = CurveCreator::Dim3d;
155 aDim = CurveCreator::Dim2d;
156 myCurve = new CurveCreator_Curve(aDim);
157 QList<PolylineSection> aPolylineData = myEditedObject->getPolylineData();
159 CurveCreator_CurveEditor* anEdit = new CurveCreator_CurveEditor(myCurve);
160 for( int i = 0 ; i < aPolylineData.size() ; i++ ){
161 std::string aName = HYDROGUI_Tool::ToQString(aPolylineData[i].mySectionName).toStdString();
162 bool isClosed = aPolylineData[i].myIsClosed;
163 CurveCreator::Type aType = CurveCreator::Polyline;
164 if( aPolylineData[i].myType == PolylineSection::SECTION_SPLINE ){
165 aType = CurveCreator::BSpline;
167 CurveCreator::Coordinates aCoords;
168 for( int j = 0 ; j < aPolylineData[i].myCoords.size() ; j++ ){
169 aCoords.push_back(aPolylineData[i].myCoords[j]);
171 anEdit->addSection( aName, aType, isClosed, aCoords );
174 aPanel->setPolylineName( myEditedObject->GetName() );
178 myCurve = new CurveCreator_Curve(CurveCreator::Dim2d);
179 aPanel->setCurve(myCurve);
180 QString aNewName = HYDROGUI_Tool::GenerateObjectName( module(), "Polyline" );
181 aPanel->setPolylineName(aNewName);
183 aPanel->setCurve(myCurve);
185 myAISCurve->setCurve(myCurve);
191 void HYDROGUI_PolylineOp::onEditorSelectionChanged()
193 HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
200 QList<int> aSelSections = aPanel->getSelectedSections();
201 for( int i = 0 ; i < myCurve->getNbSections() ; i++ ){
203 if( aSelSections.contains(i) ){
204 myAISCurve->highlightSection(i, aIsHl);