Revolution feature: Midplane and Reversed options

This commit is contained in:
jrheinlaender 2012-06-08 20:07:18 +04:30 committed by wmayer
parent 85342cd8ae
commit 58a02d24ae
5 changed files with 104 additions and 24 deletions

View File

@ -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,13 +154,27 @@ 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<double>(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());
// Reverse angle if selected
double angle = Base::toRadians<double>(Angle.getValue());
if (Reversed.getValue() && !Midplane.getValue())
angle *= (-1.0);
try {
// revolve the face to a solid
BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()));
BRepPrimAPI_MakeRevol RevolMaker(aFace.Moved(invObjLoc), gp_Ax1(pnt, dir), angle);
if (RevolMaker.IsDone()) {
TopoDS_Shape result = RevolMaker.Shape();
@ -181,5 +198,10 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
}

View File

@ -40,6 +40,8 @@ public:
App::PropertyVector Base;
App::PropertyVector Axis;
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

View File

@ -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<PartDesign::Revolution*>(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<PartDesign::Revolution*>(RevolutionView->getObject());
pcRevolution->Midplane.setValue(on);
pcRevolution->getDocument()->recomputeFeature(pcRevolution);
}
void TaskRevolutionParameters::onReversed(bool on)
{
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(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();

View File

@ -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);

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>182</width>
<height>68</height>
<width>278</width>
<height>158</height>
</rect>
</property>
<property name="windowTitle">
@ -54,7 +54,7 @@
<number>1</number>
</property>
<property name="minimum">
<double>-360.000000000000000</double>
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>360.000000000000000</double>
@ -69,6 +69,23 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxMidplane">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Symmetric to plane</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxReversed">
<property name="text">
<string>Reversed</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>