From 7c95f25abf3ee7a28d2edaa168ddffbb458301bf Mon Sep 17 00:00:00 2001 From: balazs-bamer Date: Thu, 29 Jan 2015 11:24:44 +0100 Subject: [PATCH] Warning for surfaces with 2 edges only If the user creates a surface from 2 edges, a warning dialog appears. Some refactoring in Command.cpp to make it simpler. --- src/Mod/Surface/Gui/Command.cpp | 41 ++++++++++----------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 1e0a416c6a..d6425fbc35 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -161,8 +161,7 @@ protected: bool willBezier; bool willBSpline; virtual bool isActive(void); - void createBezier(void); - void createBSpline(void); + void createSurface(const char *surfaceNamePrefix, const char *commandName, const char *pythonAddCommand); virtual void activated(int iMsg); }; @@ -239,41 +238,25 @@ bool CmdSurfaceBSurf::isActive(void) return true; } -void CmdSurfaceBSurf::createBezier() +void CmdSurfaceBSurf::createSurface(const char *surfaceNamePrefix, const char *commandName, const char *pythonAddCommand) { // we take the whole selection and require that all of its members are of the required curve - std::vector Selo = getSelection().getSelectionEx(0); - std::string FeatName = getUniqueObjectName("BezierSurface"); - std::stringstream bezListCmd; - bezListCmd << "FreeCAD.ActiveDocument.ActiveObject.aBList = ["; - for (std::vector::iterator it = Selo.begin(); it != Selo.end(); ++it) { - bezListCmd << "(App.activeDocument()." << it->getFeatName() << ", \'Edge1\'),"; + std::vector sel = getSelection().getSelectionEx(0); + if (sel.size() == 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Warning"), + QObject::tr("Surfaces with two edges may fail for some fill types.")); } - bezListCmd << "]"; - openCommand("Create Bezier surface"); - doCommand(Doc,"FreeCAD.ActiveDocument.addObject(\"Surface::BezSurf\",\"%s\")", FeatName.c_str()); - // invalid fill type meaning the surface is just created and cancel should delete it - doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.filltype=0"); - doCommand(Doc, "Gui.ActiveDocument.setEdit('%s',0)", FeatName.c_str()); - doCommand(Doc, bezListCmd.str().c_str()); - updateActive(); -} - -void CmdSurfaceBSurf::createBSpline() -{ - // we take the whole selection and require that all of its members are of the required curve - std::vector Selo = getSelection().getSelectionEx(0); - std::string FeatName = getUniqueObjectName("BSplineSurface"); + std::string FeatName = getUniqueObjectName(surfaceNamePrefix); std::stringstream bspListCmd; bspListCmd << "FreeCAD.ActiveDocument.ActiveObject.aBList = ["; - for (std::vector::iterator it = Selo.begin(); it != Selo.end(); ++it) { + for (std::vector::iterator it = sel.begin(); it != sel.end(); ++it) { bspListCmd << "(App.activeDocument()." << it->getFeatName() << ", \'Edge1\'),"; } bspListCmd << "]"; - openCommand("Create BSpline surface"); - doCommand(Doc,"FreeCAD.ActiveDocument.addObject(\"Surface::BSplineSurf\",\"%s\")", FeatName.c_str()); + openCommand(commandName); + doCommand(Doc, pythonAddCommand, FeatName.c_str()); // invalid fill type meaning the surface is just created and cancel should delete it doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.filltype=0"); doCommand(Doc, bspListCmd.str().c_str()); @@ -286,12 +269,12 @@ void CmdSurfaceBSurf::activated(int iMsg) // check wich was activated and perfom it clearing the flag if(willBezier) { - createBezier(); + createSurface("BezierSurface", "Create Bezier surface", "FreeCAD.ActiveDocument.addObject(\"Surface::BezSurf\",\"%s\")"); willBezier = false; } if(willBSpline) { - createBSpline(); + createSurface("BSplineSurface", "Create BSpline surface", "FreeCAD.ActiveDocument.addObject(\"Surface::BSplineSurf\",\"%s\")"); willBSpline = false; } }