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(Axis,(Base::Vector3f(0.0f,1.0f,0.0f)));
ADD_PROPERTY(Angle,(360.0)); ADD_PROPERTY(Angle,(360.0));
ADD_PROPERTY_TYPE(ReferenceAxis,(0),"Revolution",(App::PropertyType)(App::Prop_None),"Reference axis of revolution"); 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 short Revolution::mustExecute() const
@ -65,7 +67,8 @@ short Revolution::mustExecute() const
ReferenceAxis.isTouched() || ReferenceAxis.isTouched() ||
Axis.isTouched() || Axis.isTouched() ||
Base.isTouched() || Base.isTouched() ||
Angle.isTouched()) Angle.isTouched() ||
Midplane.isTouched())
return 1; return 1;
return 0; return 0;
} }
@ -151,13 +154,27 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
if (aFace.IsNull()) if (aFace.IsNull())
return new App::DocumentObjectExecReturn("Creating a face from sketch failed"); 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(); this->positionBySketch();
TopLoc_Location invObjLoc = this->getLocation().Inverted(); TopLoc_Location invObjLoc = this->getLocation().Inverted();
pnt.Transform(invObjLoc.Transformation()); pnt.Transform(invObjLoc.Transformation());
dir.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 // 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()) { if (RevolMaker.IsDone()) {
TopoDS_Shape result = RevolMaker.Shape(); TopoDS_Shape result = RevolMaker.Shape();
@ -181,5 +198,10 @@ App::DocumentObjectExecReturn *Revolution::execute(void)
return App::DocumentObject::StdReturn; 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 Base;
App::PropertyVector Axis; 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 /** if this property is set to a valid link, both Axis and Base properties
* are calculated according to the linked line * are calculated according to the linked line

View File

@ -60,11 +60,18 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol
this, SLOT(onAngleChanged(double))); this, SLOT(onAngleChanged(double)));
connect(ui->axis, SIGNAL(activated(int)), connect(ui->axis, SIGNAL(activated(int)),
this, SLOT(onAxisChanged(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); this->groupLayout()->addWidget(proxy);
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject()); PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(RevolutionView->getObject());
double l = pcRevolution->Angle.getValue(); double l = pcRevolution->Angle.getValue();
bool mirrored = pcRevolution->Midplane.getValue();
bool reversed = pcRevolution->Reversed.getValue();
ui->doubleSpinBox->setValue(l); ui->doubleSpinBox->setValue(l);
int count=pcRevolution->getSketchAxisCount(); int count=pcRevolution->getSketchAxisCount();
@ -95,6 +102,9 @@ TaskRevolutionParameters::TaskRevolutionParameters(ViewProviderRevolution *Revol
ui->axis->setCurrentIndex(pos); ui->axis->setCurrentIndex(pos);
ui->checkBoxMidplane->setChecked(mirrored);
ui->checkBoxReversed->setChecked(reversed);
setFocus (); setFocus ();
} }
@ -126,6 +136,19 @@ void TaskRevolutionParameters::onAxisChanged(int num)
pcRevolution->getDocument()->recomputeFeature(pcRevolution); 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 double TaskRevolutionParameters::getAngle(void) const
{ {
@ -157,6 +180,16 @@ QString TaskRevolutionParameters::getReferenceAxis(void) const
return buf; return buf;
} }
bool TaskRevolutionParameters::getMidplane(void) const
{
return ui->checkBoxMidplane->isChecked();
}
bool TaskRevolutionParameters::getReversed(void) const
{
return ui->checkBoxReversed->isChecked();
}
TaskRevolutionParameters::~TaskRevolutionParameters() TaskRevolutionParameters::~TaskRevolutionParameters()
{ {
delete ui; 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()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle());
std::string axis = parameter->getReferenceAxis().toStdString(); 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.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::Doc,"App.ActiveDocument.recompute()");
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
Gui::Command::commitCommand(); Gui::Command::commitCommand();

View File

@ -54,10 +54,14 @@ public:
QString getReferenceAxis(void) const; QString getReferenceAxis(void) const;
double getAngle(void) const; double getAngle(void) const;
bool getMidplane(void) const;
bool getReversed(void) const;
private Q_SLOTS: private Q_SLOTS:
void onAngleChanged(double); void onAngleChanged(double);
void onAxisChanged(int); void onAxisChanged(int);
void onMidplane(bool);
void onReversed(bool);
protected: protected:
void changeEvent(QEvent *e); void changeEvent(QEvent *e);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>182</width> <width>278</width>
<height>68</height> <height>158</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -54,7 +54,7 @@
<number>1</number> <number>1</number>
</property> </property>
<property name="minimum"> <property name="minimum">
<double>-360.000000000000000</double> <double>0.000000000000000</double>
</property> </property>
<property name="maximum"> <property name="maximum">
<double>360.000000000000000</double> <double>360.000000000000000</double>
@ -69,6 +69,23 @@
</item> </item>
</layout> </layout>
</item> </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> </layout>
</widget> </widget>
<resources/> <resources/>