#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Vertex.hxx>
-#include <TopoDS_Face.hxx>
//#define DEB_CHANNEL 1
#ifdef DEB_CHANNEL
return getShape3D();
}
-void HYDROData_Channel::Update()
+bool HYDROData_Channel::CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine,
+ const Handle(HYDROData_Profile)& theProfile,
+ PrsDefinition& thePrs )
{
- HYDROData_ArtificialObject::Update();
-
- Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
- Handle(HYDROData_Profile) aProfile = GetProfile();
- if ( aGuideLine.IsNull() || aProfile.IsNull() )
- return;
+ if ( theGuideLine.IsNull() || theProfile.IsNull() )
+ return false;
// build 3d shape
- TopoDS_Wire aPathWire = TopoDS::Wire(aGuideLine->GetShape3D());
- if(aPathWire.IsNull())
- return;
- TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetShape3D() );
- if(aProfileWire.IsNull())
- return;
+ TopoDS_Wire aPathWire = TopoDS::Wire( theGuideLine->GetShape3D() );
+ TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetShape3D() );
+ if ( aPathWire.IsNull() || aProfileWire.IsNull() )
+ return false;
#ifdef DEB_CHANNEL
BRepTools::Write( aPathWire, "guideline.brep" );
HYDROData_Canal3dAnd2d aChannelConstructor( aProfileWire, aPathWire );
if( aChannelConstructor.GetStatus() != 0 )
- return;
+ return false;
aChannelConstructor.Create3dPresentation();
aChannelConstructor.Create2dPresentation();
- SetShape3D( aChannelConstructor.Get3dPresentation() );
- SetTopShape( aChannelConstructor.Get2dPresentation() );
+ thePrs.myPrs3D = aChannelConstructor.Get3dPresentation();
+ thePrs.myPrs2D = aChannelConstructor.Get2dPresentation();
+
+ thePrs.myLeftBank = aChannelConstructor.GetLeftBank();
+ thePrs.myRightBank = aChannelConstructor.GetRightBank();
+ thePrs.myInlet = aChannelConstructor.GetInlet();
+ thePrs.myOutlet = aChannelConstructor.GetOutlet();
#ifdef DEB_CHANNEL
- BRepTools::Write( aChannelConstructor.Get2dPresentation(), "channel2d.brep" );
- BRepTools::Write( aChannelConstructor.Get3dPresentation(), "channel3d.brep" );
+ BRepTools::Write( thePrs.myPrs2D, "channel2d.brep" );
+ BRepTools::Write( thePrs.myPrs3D, "channel3d.brep" );
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", thePrs.myPrs2D, TopAbs_EDGE );
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", thePrs.myLeftBank, TopAbs_EDGE );
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", thePrs.myRightBank, TopAbs_EDGE );
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", thePrs.myInlet, TopAbs_EDGE );
+ HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", thePrs.myOutlet, TopAbs_EDGE );
#endif
- TopAbs_ShapeEnum aType = GetTopShape().ShapeType();
+ return true;
+}
- // Create groups for channel
- TopoDS_Wire aLeftBank = aChannelConstructor.GetLeftBank();
- TopoDS_Wire aRightBank = aChannelConstructor.GetRightBank();
- TopoDS_Wire anInlet = aChannelConstructor.GetInlet();
- TopoDS_Wire anOutlet = aChannelConstructor.GetOutlet();
+void HYDROData_Channel::Update()
+{
+ HYDROData_ArtificialObject::Update();
-#ifdef DEB_CHANNEL
- HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Top shape edges:", GetTopShape(), TopAbs_EDGE );
- HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Left bank edges:", aLeftBank, TopAbs_EDGE );
- HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Right bank edges:", aRightBank, TopAbs_EDGE );
- HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Inlet edges:", anInlet, TopAbs_EDGE );
- HYDROData_ShapesTool::DumpShapeSubShapes( std::cout, "Outlet edges:", anOutlet, TopAbs_EDGE );
-#endif
+ Handle(HYDROData_Polyline3D) aGuideLine = GetGuideLine();
+ Handle(HYDROData_Profile) aProfile = GetProfile();
+
+ PrsDefinition aResultPrs;
+ if ( !CreatePresentaions( aGuideLine, aProfile, aResultPrs ) )
+ return;
+
+ SetShape3D( aResultPrs.myPrs3D );
+ SetTopShape( aResultPrs.myPrs2D );
+ // Create groups for channel
TopTools_SequenceOfShape aLeftBankEdges;
- HYDROData_ShapesTool::ExploreShapeToShapes( aLeftBank, TopAbs_EDGE, aLeftBankEdges );
+ HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myLeftBank, TopAbs_EDGE, aLeftBankEdges );
TopTools_SequenceOfShape aRightBankEdges;
- HYDROData_ShapesTool::ExploreShapeToShapes( aRightBank, TopAbs_EDGE, aRightBankEdges );
+ HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myRightBank, TopAbs_EDGE, aRightBankEdges );
TopTools_SequenceOfShape anInletEdges;
- HYDROData_ShapesTool::ExploreShapeToShapes( anInlet, TopAbs_EDGE, anInletEdges );
+ HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myInlet, TopAbs_EDGE, anInletEdges );
TopTools_SequenceOfShape anOutletEdges;
- HYDROData_ShapesTool::ExploreShapeToShapes( anOutlet, TopAbs_EDGE, anOutletEdges );
+ HYDROData_ShapesTool::ExploreShapeToShapes( aResultPrs.myOutlet, TopAbs_EDGE, anOutletEdges );
QString aLeftGroupName = GetName() + "_Left_Bank";
#include "HYDROData_ArtificialObject.h"
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Wire.hxx>
+
class Handle(HYDROData_Polyline3D);
class Handle(HYDROData_Profile);
class TopTools_SequenceOfShape;
*/
class HYDROData_Channel : public HYDROData_ArtificialObject
{
+public:
+
+ struct PrsDefinition
+ {
+ TopoDS_Shape myPrs3D;
+ TopoDS_Face myPrs2D;
+ TopoDS_Wire myLeftBank;
+ TopoDS_Wire myRightBank;
+ TopoDS_Wire myInlet;
+ TopoDS_Wire myOutlet;
+ };
+
protected:
/**
* Enumeration of tags corresponding to the persistent object parameters.
};
public:
+
DEFINE_STANDARD_RTTI(HYDROData_Channel);
+public:
+
+ /**
+ * Creates the presentation by given guide line and profile.
+ */
+ HYDRODATA_EXPORT static bool CreatePresentaions( const Handle(HYDROData_Polyline3D)& theGuideLine,
+ const Handle(HYDROData_Profile)& theProfile,
+ PrsDefinition& thePrs );
+
+public:
+
/**
* Returns the kind of this object. Must be redefined in all objects of known type.
*/
{
HYDROGUI_Operation::startOperation();
- // We start operation in the document
- startDocOperation();
-
HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
aPanel->blockSignals( true );
aPanel->reset();
- myEditedObject = getObjectToEdit();
+ myEditedObject.Nullify();
QString aSelectedGuideLine, aSelectedProfile;
QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_CHANNEL_NAME" ) );
- if ( myIsEdit && !myEditedObject.IsNull() )
+ if ( myIsEdit )
{
- anObjectName = myEditedObject->GetName();
+ myEditedObject =
+ Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ if ( !myEditedObject.IsNull() )
+ {
+ anObjectName = myEditedObject->GetName();
- Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
- if ( !aRefGuideLine.IsNull() )
- aSelectedGuideLine = aRefGuideLine->GetName();
+ Handle(HYDROData_Polyline3D) aRefGuideLine = myEditedObject->GetGuideLine();
+ if ( !aRefGuideLine.IsNull() )
+ aSelectedGuideLine = aRefGuideLine->GetName();
- Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
- if ( !aRefProfile.IsNull() )
- aSelectedProfile = aRefProfile->GetName();
+ Handle(HYDROData_Profile) aRefProfile = myEditedObject->GetProfile();
+ if ( !aRefProfile.IsNull() )
+ aSelectedProfile = aRefProfile->GetName();
+ }
}
// collect information about existing 3d polylines
QStringList aGuideLines;
- QStringList anAllGuideLines = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_POLYLINE );
- foreach( QString aGuideLine, anAllGuideLines )
+ HYDROData_Iterator aPolylinesIt( doc(), KIND_POLYLINE );
+ for ( ; aPolylinesIt.More(); aPolylinesIt.Next() )
{
- Handle( HYDROData_Polyline3D ) aPolyline3d =
- Handle( HYDROData_Polyline3D )::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aGuideLine, KIND_POLYLINE ) );
+ Handle(HYDROData_Polyline3D) aPolyline3d =
+ Handle(HYDROData_Polyline3D)::DownCast( aPolylinesIt.Current() );
if( !aPolyline3d.IsNull() )
{
TopoDS_Shape aShape = aPolyline3d->GetShape3D();
{
TopoDS_Wire aWire = TopoDS::Wire( aShape );
if( !aWire.Closed() )
- aGuideLines.append( aGuideLine );
+ aGuideLines.append( aPolyline3d->GetName() );
}
}
}
aPanel->blockSignals( false );
- onCreatePreview( true );
+ onCreatePreview();
}
-
void HYDROGUI_ChannelOp::abortOperation()
{
erasePreview();
- abortDocOperation();
-
HYDROGUI_Operation::abortOperation();
}
void HYDROGUI_ChannelOp::commitOperation()
{
erasePreview();
-
HYDROGUI_Operation::commitOperation();
}
}
}
+
if ( myEditedObject.IsNull() )
- return false;
+ myEditedObject = createNewObject(); // Create new data model object
myEditedObject->SetName( anObjectName );
if ( !myIsEdit )
{
- myEditedObject->SetFillingColor( HYDROData_Channel::DefaultFillingColor() );
- myEditedObject->SetBorderColor( HYDROData_Channel::DefaultBorderColor() );
+ myEditedObject->SetFillingColor( getDefaultFillingColor() );
+ myEditedObject->SetBorderColor( getDefaultBorderColor() );
}
+ QString aGuideLineName = aPanel->getGuideLineName();
+ QString aProfileName = aPanel->getProfileName();
+ if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
+ {
+ myEditedObject->RemoveGuideLine();
+ myEditedObject->RemoveProfile();
+ }
+ else
+ {
+ Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
+ myEditedObject->SetGuideLine( aGuideLine );
+
+ Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
+ myEditedObject->SetProfile( aProfile );
+ }
+
+ if ( myEditedObject->IsMustBeUpdated() )
+ myEditedObject->Update();
+
erasePreview();
if( !myIsEdit )
return true;
}
-Handle(HYDROData_Channel) HYDROGUI_ChannelOp::getObjectToEdit() const
+Handle(HYDROData_Channel) HYDROGUI_ChannelOp::createNewObject() const
+{
+ return Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
+}
+
+QColor HYDROGUI_ChannelOp::getDefaultFillingColor() const
+{
+ return HYDROData_Channel::DefaultFillingColor();
+}
+
+QColor HYDROGUI_ChannelOp::getDefaultBorderColor() const
{
- return myIsEdit ? Handle(HYDROData_Channel)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) :
- Handle(HYDROData_Channel)::DownCast( doc()->CreateObject( KIND_CHANNEL ) );
+ return HYDROData_Channel::DefaultBorderColor();
}
-void HYDROGUI_ChannelOp::onCreatePreview( const bool theIsInit )
+void HYDROGUI_ChannelOp::onCreatePreview()
{
HYDROGUI_ChannelDlg* aPanel = ::qobject_cast<HYDROGUI_ChannelDlg*>( inputPanel() );
- if ( !aPanel || myEditedObject.IsNull() )
+ if ( !aPanel )
return;
QString aGuideLineName = aPanel->getGuideLineName();
QString aProfileName = aPanel->getProfileName();
if ( aGuideLineName.isEmpty() || aProfileName.isEmpty() )
{
- if ( !theIsInit )
- {
- myEditedObject->RemoveGuideLine();
- myEditedObject->RemoveProfile();
- myEditedObject->Update();
- }
-
erasePreview();
return;
}
- // Update channel data
- if ( !theIsInit )
- {
- Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
- myEditedObject->SetGuideLine( aGuideLine );
-
- Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
- HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
- myEditedObject->SetProfile( aProfile );
-
- if ( myEditedObject->IsMustBeUpdated() )
- myEditedObject->Update();
- }
-
LightApp_Application* anApp = module()->getApp();
if ( !getPreviewManager() )
+ {
setPreviewManager( ::qobject_cast<OCCViewer_ViewManager*>(
anApp->getViewManager( OCCViewer_Viewer::Type(), true ) ) );
+ }
OCCViewer_ViewManager* aViewManager = getPreviewManager();
if ( aViewManager && !myPreviewPrs )
{
Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
if ( !aCtx.IsNull() )
- myPreviewPrs = new HYDROGUI_Shape( aCtx, myEditedObject, getPreviewZLayer() );
+ myPreviewPrs = new HYDROGUI_Shape( aCtx, NULL, getPreviewZLayer() );
}
}
if ( !aViewManager || !myPreviewPrs )
return;
- myPreviewPrs->update( true );
+ Handle(HYDROData_Polyline3D) aGuideLine = Handle(HYDROData_Polyline3D)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aGuideLineName, KIND_POLYLINE ) );
+
+ Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast(
+ HYDROGUI_Tool::FindObjectByName( module(), aProfileName, KIND_PROFILE ) );
+
+ HYDROData_Channel::PrsDefinition aPrsDef;
+ if ( !HYDROData_Channel::CreatePresentaions( aGuideLine, aProfile, aPrsDef ) )
+ {
+ erasePreview();
+ return;
+ }
+
+ QColor aFillingColor = getDefaultFillingColor();
+ QColor aBorderColor = getDefaultBorderColor();
+ if ( !myEditedObject.IsNull() )
+ {
+ aFillingColor = myEditedObject->GetFillingColor();
+ aBorderColor = myEditedObject->GetBorderColor();
+ }
+
+ myPreviewPrs->setFillingColor( aFillingColor, false, false );
+ myPreviewPrs->setBorderColor( aBorderColor, false, false );
+
+ myPreviewPrs->setShape( aPrsDef.myPrs2D );
}
void HYDROGUI_ChannelOp::erasePreview()
virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg );
protected slots:
- virtual void onCreatePreview( const bool theIsInit = false );
+ virtual void onCreatePreview();
protected:
virtual void erasePreview();
- virtual Handle(HYDROData_Channel) getObjectToEdit() const;
+ virtual Handle(HYDROData_Channel) createNewObject() const;
- virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; };
+ virtual QColor getDefaultFillingColor() const;
+
+ virtual QColor getDefaultBorderColor() const;
+
+ virtual HYDROGUI_Shape* getPreviewShape() const { return myPreviewPrs; };
protected:
bool myIsEdit;
return aPanel;
}
-Handle(HYDROData_Channel) HYDROGUI_DigueOp::getObjectToEdit() const
+Handle(HYDROData_Channel) HYDROGUI_DigueOp::createNewObject() const
{
- return myIsEdit ? Handle(HYDROData_Digue)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) ) :
- Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) );
+ return Handle(HYDROData_Digue)::DownCast( doc()->CreateObject( KIND_DIGUE ) );
+}
+
+QColor HYDROGUI_DigueOp::getDefaultFillingColor() const
+{
+ return HYDROData_Digue::DefaultFillingColor();
+}
+
+QColor HYDROGUI_DigueOp::getDefaultBorderColor() const
+{
+ return HYDROData_Digue::DefaultBorderColor();
}
protected:
- virtual Handle(HYDROData_Channel) getObjectToEdit() const;
+ virtual Handle(HYDROData_Channel) createNewObject() const;
+
+ virtual QColor getDefaultFillingColor() const;
+
+ virtual QColor getDefaultBorderColor() const;
private: