Sketcher: Shape to NURBS conversion
This commit is contained in:
parent
90bec55660
commit
d5b068e0ab
|
@ -3766,6 +3766,43 @@ int SketchObject::DeleteUnusedInternalGeometry(int GeoId, bool delgeoid)
|
|||
}
|
||||
}
|
||||
|
||||
bool SketchObject::ConvertToNURBS(int GeoId)
|
||||
{
|
||||
if (GeoId < 0 || GeoId > getHighestCurveIndex())
|
||||
return -1;
|
||||
|
||||
const Part::Geometry *geo = getGeometry(GeoId);
|
||||
|
||||
if(geo->getTypeId() == Part::GeomPoint::getClassTypeId())
|
||||
return -1;
|
||||
|
||||
const Part::GeomCurve *geo1 = static_cast<const Part::GeomCurve *>(geo);
|
||||
|
||||
Part::GeomBSplineCurve* bspline;
|
||||
|
||||
try {
|
||||
bspline = geo1->toNurbs(geo1->getFirstParameter(), geo1->getLastParameter());
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Error("%s\n", e.what());
|
||||
// revert to original values
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::vector< Part::Geometry * > &vals = getInternalGeometry();
|
||||
|
||||
std::vector< Part::Geometry * > newVals(vals);
|
||||
|
||||
newVals[GeoId] = bspline;
|
||||
|
||||
Geometry.setValues(newVals);
|
||||
Constraints.acceptGeometry(getCompleteGeometry());
|
||||
rebuildVertexIndex();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
int SketchObject::addExternal(App::DocumentObject *Obj, const char* SubName)
|
||||
{
|
||||
// so far only externals to the support of the sketch and datum features
|
||||
|
|
|
@ -196,6 +196,8 @@ public:
|
|||
\retval int - returns -1 on error, otherwise the number of deleted elements
|
||||
*/
|
||||
int DeleteUnusedInternalGeometry(int GeoId, bool delgeoid=false);
|
||||
|
||||
bool ConvertToNURBS(int GeoId);
|
||||
|
||||
/// retrieves for a Vertex number the corresponding GeoId and PosId
|
||||
void getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId) const;
|
||||
|
|
|
@ -296,7 +296,63 @@ bool CmdSketcherCompBSplineShowHideGeometryInformation::isActive(void)
|
|||
return isSketcherBSplineActive( getActiveGuiDocument(), false );
|
||||
}
|
||||
|
||||
// Convert to NURB
|
||||
DEF_STD_CMD_A(CmdSketcherConvertToNURB);
|
||||
|
||||
CmdSketcherConvertToNURB::CmdSketcherConvertToNURB()
|
||||
:Command("Sketcher_BSplineConvertToNURB")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
sMenuText = QT_TR_NOOP("Convert Geometry to B-Spline");
|
||||
sToolTipText = QT_TR_NOOP("Converts the given Geometry to a B-Spline");
|
||||
sWhatsThis = "Sketcher_ConvertToNURB";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "Sketcher_ConvertToNURB";
|
||||
sAccel = "";
|
||||
eType = ForEdit;
|
||||
}
|
||||
|
||||
void CmdSketcherConvertToNURB::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
|
||||
// get the selection
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
|
||||
// only one sketch with its subelements are allowed to be selected
|
||||
if (selection.size() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the needed lists and objects
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
Sketcher::SketchObject* Obj = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
||||
|
||||
for (unsigned int i=0; i<SubNames.size(); i++ ) {
|
||||
// only handle edges
|
||||
if (SubNames[i].size() > 4 && SubNames[i].substr(0,4) == "Edge") {
|
||||
|
||||
int GeoId = std::atoi(SubNames[i].substr(4,4000).c_str()) - 1;
|
||||
|
||||
Obj->ConvertToNURBS(GeoId);
|
||||
}
|
||||
}
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher");
|
||||
bool autoRecompute = hGrp->GetBool("AutoRecompute",false);
|
||||
|
||||
if (autoRecompute)
|
||||
Gui::Command::updateActive();
|
||||
else
|
||||
Obj->solve();
|
||||
|
||||
}
|
||||
|
||||
bool CmdSketcherConvertToNURB::isActive(void)
|
||||
{
|
||||
return isSketcherBSplineActive( getActiveGuiDocument(), false );
|
||||
}
|
||||
|
||||
|
||||
void CreateSketcherCommandsBSpline(void)
|
||||
|
@ -307,4 +363,5 @@ void CreateSketcherCommandsBSpline(void)
|
|||
rcCmdMgr.addCommand(new CmdSketcherBSplinePolygon());
|
||||
rcCmdMgr.addCommand(new CmdSketcherBSplineComb());
|
||||
rcCmdMgr.addCommand(new CmdSketcherCompBSplineShowHideGeometryInformation());
|
||||
rcCmdMgr.addCommand(new CmdSketcherConvertToNURB());
|
||||
}
|
||||
|
|
|
@ -285,12 +285,14 @@ template <>
|
|||
inline void SketcherAddWorkbenchBSplines<Gui::MenuItem>(Gui::MenuItem& bspline){
|
||||
bspline << "Sketcher_BSplineDegree"
|
||||
<< "Sketcher_BSplinePolygon"
|
||||
<< "Sketcher_BSplineComb";
|
||||
<< "Sketcher_BSplineComb"
|
||||
<< "Sketcher_BSplineConvertToNURB";
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void SketcherAddWorkbenchBSplines<Gui::ToolBarItem>(Gui::ToolBarItem& bspline){
|
||||
bspline << "Sketcher_CompBSplineShowHideGeometryInformation";
|
||||
bspline << "Sketcher_CompBSplineShowHideGeometryInformation"
|
||||
<< "Sketcher_BSplineConvertToNURB";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in New Issue
Block a user