From 58a02d24ae2ad93a6d8a7321d44a37fc88c105b7 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Fri, 8 Jun 2012 20:07:18 +0430 Subject: [PATCH] Revolution feature: Midplane and Reversed options --- src/Mod/PartDesign/App/FeatureRevolution.cpp | 62 +++++++++++++------ src/Mod/PartDesign/App/FeatureRevolution.h | 4 +- .../Gui/TaskRevolutionParameters.cpp | 35 +++++++++++ .../PartDesign/Gui/TaskRevolutionParameters.h | 4 ++ .../Gui/TaskRevolutionParameters.ui | 23 ++++++- 5 files changed, 104 insertions(+), 24 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index 317aa52d1..1a14783ae 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -56,6 +56,8 @@ Revolution::Revolution() ADD_PROPERTY(Axis,(Base::Vector3f(0.0f,1.0f,0.0f))); ADD_PROPERTY(Angle,(360.0)); ADD_PROPERTY_TYPE(ReferenceAxis,(0),"Revolution",(App::PropertyType)(App::Prop_None),"Reference axis of revolution"); + ADD_PROPERTY(Midplane,(0)); + ADD_PROPERTY(Reversed, (0)); } short Revolution::mustExecute() const @@ -65,7 +67,8 @@ short Revolution::mustExecute() const ReferenceAxis.isTouched() || Axis.isTouched() || Base.isTouched() || - Angle.isTouched()) + Angle.isTouched() || + Midplane.isTouched()) return 1; return 0; } @@ -151,35 +154,54 @@ App::DocumentObjectExecReturn *Revolution::execute(void) if (aFace.IsNull()) return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); + // Rotate the face by half the angle to get revolution symmetric to sketch plane + if (Midplane.getValue()) { + gp_Trsf mov; + mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians(Angle.getValue()) * (-1.0) / 2.0); + TopLoc_Location loc(mov); + aFace.Move(loc); + } + this->positionBySketch(); TopLoc_Location invObjLoc = this->getLocation().Inverted(); pnt.Transform(invObjLoc.Transformation()); dir.Transform(invObjLoc.Transformation()); - // revolve the face to a solid - BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), Base::toRadians(Angle.getValue())); + // Reverse angle if selected + double angle = Base::toRadians(Angle.getValue()); + if (Reversed.getValue() && !Midplane.getValue()) + angle *= (-1.0); - if (RevolMaker.IsDone()) { - TopoDS_Shape result = RevolMaker.Shape(); - // if the sketch has a support fuse them to get one result object (PAD!) - if (SupportObject) { - const TopoDS_Shape& support = SupportObject->Shape.getValue(); - if (!support.IsNull() && support.ShapeType() == TopAbs_SOLID) { - // Let's call algorithm computing a fuse operation: - BRepAlgoAPI_Fuse mkFuse(support.Moved(invObjLoc), result); - // Let's check if the fusion has been successful - if (!mkFuse.IsDone()) - throw Base::Exception("Fusion with support failed"); - result = mkFuse.Shape(); + try { + // revolve the face to a solid + BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), angle); + + if (RevolMaker.IsDone()) { + TopoDS_Shape result = RevolMaker.Shape(); + // if the sketch has a support fuse them to get one result object (PAD!) + if (SupportObject) { + const TopoDS_Shape& support = SupportObject->Shape.getValue(); + if (!support.IsNull() && support.ShapeType() == TopAbs_SOLID) { + // Let's call algorithm computing a fuse operation: + BRepAlgoAPI_Fuse mkFuse(support.Moved(invObjLoc), result); + // Let's check if the fusion has been successful + if (!mkFuse.IsDone()) + throw Base::Exception("Fusion with support failed"); + result = mkFuse.Shape(); + } } + + this->Shape.setValue(result); } + else + return new App::DocumentObjectExecReturn("Could not revolve the sketch!"); - this->Shape.setValue(result); + return App::DocumentObject::StdReturn; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + return new App::DocumentObjectExecReturn(e->GetMessageString()); } - else - return new App::DocumentObjectExecReturn("Could not revolve the sketch!"); - - return App::DocumentObject::StdReturn; } } diff --git a/src/Mod/PartDesign/App/FeatureRevolution.h b/src/Mod/PartDesign/App/FeatureRevolution.h index 4d6677d54..ed11adc06 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.h +++ b/src/Mod/PartDesign/App/FeatureRevolution.h @@ -39,7 +39,9 @@ public: App::PropertyVector Base; App::PropertyVector Axis; - App::PropertyAngle Angle; + App::PropertyAngle Angle; + App::PropertyBool Midplane; + App::PropertyBool Reversed; /** if this property is set to a valid link, both Axis and Base properties * are calculated according to the linked line diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 05b01058f..f78134b74 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -60,11 +60,18 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol this, SLOT(onAngleChanged(double))); connect(ui->axis, SIGNAL(activated(int)), this, SLOT(onAxisChanged(int))); + connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)), + this, SLOT(onMidplane(bool))); + connect(ui->checkBoxReversed, SIGNAL(toggled(bool)), + this, SLOT(onReversed(bool))); this->groupLayout()->addWidget(proxy); PartDesign::Revolution* pcRevolution = static_cast(RevolutionView->getObject()); double l = pcRevolution->Angle.getValue(); + bool mirrored = pcRevolution->Midplane.getValue(); + bool reversed = pcRevolution->Reversed.getValue(); + ui->doubleSpinBox->setValue(l); int count=pcRevolution->getSketchAxisCount(); @@ -95,6 +102,9 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol ui->axis->setCurrentIndex(pos); + ui->checkBoxMidplane->setChecked(mirrored); + ui->checkBoxReversed->setChecked(reversed); + setFocus (); } @@ -126,6 +136,19 @@ void TaskRevolutionParameters::onAxisChanged(int num) pcRevolution->getDocument()->recomputeFeature(pcRevolution); } +void TaskRevolutionParameters::onMidplane(bool on) +{ + PartDesign::Revolution* pcRevolution = static_cast(RevolutionView->getObject()); + pcRevolution->Midplane.setValue(on); + pcRevolution->getDocument()->recomputeFeature(pcRevolution); +} + +void TaskRevolutionParameters::onReversed(bool on) +{ + PartDesign::Revolution* pcRevolution = static_cast(RevolutionView->getObject()); + pcRevolution->Reversed.setValue(on); + pcRevolution->getDocument()->recomputeFeature(pcRevolution); +} double TaskRevolutionParameters::getAngle(void) const { @@ -157,6 +180,16 @@ QString TaskRevolutionParameters::getReferenceAxis(void) const return buf; } +bool TaskRevolutionParameters::getMidplane(void) const +{ + return ui->checkBoxMidplane->isChecked(); +} + +bool TaskRevolutionParameters::getReversed(void) const +{ + return ui->checkBoxReversed->isChecked(); +} + TaskRevolutionParameters::~TaskRevolutionParameters() { delete ui; @@ -210,6 +243,8 @@ bool TaskDlgRevolutionParameters::accept() Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle()); std::string axis = parameter->getReferenceAxis().toStdString(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.ReferenceAxis = %s",name.c_str(),axis.c_str()); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Midplane = %i",name.c_str(),parameter->getMidplane()?1:0); + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %i",name.c_str(),parameter->getReversed()?1:0); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::commitCommand(); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h index dcafbd618..1d9eb71a8 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h @@ -54,10 +54,14 @@ public: QString getReferenceAxis(void) const; double getAngle(void) const; + bool getMidplane(void) const; + bool getReversed(void) const; private Q_SLOTS: void onAngleChanged(double); void onAxisChanged(int); + void onMidplane(bool); + void onReversed(bool); protected: void changeEvent(QEvent *e); diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui index a80c300fe..dac292f99 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.ui @@ -6,8 +6,8 @@ 0 0 - 182 - 68 + 278 + 158 @@ -54,7 +54,7 @@ 1 - -360.000000000000000 + 0.000000000000000 360.000000000000000 @@ -69,6 +69,23 @@ + + + + true + + + Symmetric to plane + + + + + + + Reversed + + +