From 4f96fa23006dfad5d6b1fb653b0347187ecfe864 Mon Sep 17 00:00:00 2001 From: balazs-bamer Date: Thu, 20 Nov 2014 18:01:59 +0100 Subject: [PATCH] Let the Surface workbench appear and try to create a Bezier surface Modifications for: - let the surface workbench appear - use only one Surface menu and toolbar instead of two separate ones - create a Bezier surface using 2..4 Bezier curves (does not work yet) - use enums for fill type Signed-off-by: balazs-bamer --- src/Mod/Surface/App/FeatureBSplineSurf.cpp | 10 +-- src/Mod/Surface/App/FeatureBezSurf.cpp | 10 +-- src/Mod/Surface/App/FillType.h | 34 ++++++++++ src/Mod/Surface/CMakeLists.txt | 4 +- src/Mod/Surface/Gui/AppSurfaceGui.cpp | 6 +- src/Mod/Surface/Gui/Command.cpp | 72 +++++++++++++++++++++- src/Mod/Surface/Gui/Workbench.cpp | 28 ++++----- src/Mod/Surface/InitGui.py | 10 +++ 8 files changed, 145 insertions(+), 29 deletions(-) create mode 100644 src/Mod/Surface/App/FillType.h diff --git a/src/Mod/Surface/App/FeatureBSplineSurf.cpp b/src/Mod/Surface/App/FeatureBSplineSurf.cpp index 75d85dabe7..2b409705a8 100644 --- a/src/Mod/Surface/App/FeatureBSplineSurf.cpp +++ b/src/Mod/Surface/App/FeatureBSplineSurf.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) 2014 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -32,6 +33,7 @@ #endif #include "FeatureBSplineSurf.h" +#include "FillType.h" #include #include #include @@ -96,10 +98,10 @@ App::DocumentObjectExecReturn *BSplineSurf::execute(void) GeomFill_FillingStyle fstyle; - if(ftype==1){fstyle = GeomFill_StretchStyle;} - else if(ftype==2){fstyle = GeomFill_CoonsStyle;} - else if(ftype==3){fstyle = GeomFill_CurvedStyle;} - else{return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} + if(ftype==StretchStyle) {fstyle = GeomFill_StretchStyle;} + else if(ftype==CoonsStyle) {fstyle = GeomFill_CoonsStyle;} + else if(ftype==CurvedStyle) {fstyle = GeomFill_CurvedStyle;} + else {return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} //Create BSpline Surface diff --git a/src/Mod/Surface/App/FeatureBezSurf.cpp b/src/Mod/Surface/App/FeatureBezSurf.cpp index 68f396a957..b4fba9feb1 100644 --- a/src/Mod/Surface/App/FeatureBezSurf.cpp +++ b/src/Mod/Surface/App/FeatureBezSurf.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) 2014 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -32,6 +33,7 @@ #endif #include "FeatureBezSurf.h" +#include "FillType.h" #include #include #include @@ -96,10 +98,10 @@ App::DocumentObjectExecReturn *BezSurf::execute(void) GeomFill_FillingStyle fstyle; - if(ftype==1){fstyle = GeomFill_StretchStyle;} - else if(ftype==2){fstyle = GeomFill_CoonsStyle;} - else if(ftype==3){fstyle = GeomFill_CurvedStyle;} - else{return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} + if(ftype==StretchStyle) {fstyle = GeomFill_StretchStyle;} + else if(ftype==CoonsStyle) {fstyle = GeomFill_CoonsStyle;} + else if(ftype==CurvedStyle) {fstyle = GeomFill_CurvedStyle;} + else {return new App::DocumentObjectExecReturn("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");} //Create Bezier Surface diff --git a/src/Mod/Surface/App/FillType.h b/src/Mod/Surface/App/FillType.h new file mode 100644 index 0000000000..6a9b0d5a47 --- /dev/null +++ b/src/Mod/Surface/App/FillType.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * Copyright (c) 2014 Balázs Bámer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef SURFACE_FILLTYPE_H +#define SURFACE_FILLTYPE_H + +namespace Surface +{ + enum filltype_t + { + StretchStyle = 1, CoonsStyle, CurvedStyle + }; +} + +#endif \ No newline at end of file diff --git a/src/Mod/Surface/CMakeLists.txt b/src/Mod/Surface/CMakeLists.txt index b130d344ff..9d5db434d7 100644 --- a/src/Mod/Surface/CMakeLists.txt +++ b/src/Mod/Surface/CMakeLists.txt @@ -1,8 +1,8 @@ add_subdirectory(App) -if(FREECAD_BUILD_GUI) +if(BUILD_GUI) add_subdirectory(Gui) -endif(FREECAD_BUILD_GUI) +endif(BUILD_GUI) install( FILES diff --git a/src/Mod/Surface/Gui/AppSurfaceGui.cpp b/src/Mod/Surface/Gui/AppSurfaceGui.cpp index cbe0ab840c..b647a86ae4 100644 --- a/src/Mod/Surface/Gui/AppSurfaceGui.cpp +++ b/src/Mod/Surface/Gui/AppSurfaceGui.cpp @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (c) 2014 Nathan Miller * + * Copyright (c) 2014 Nathan Miller ,* + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -53,9 +54,10 @@ void PartGuiExport initSurfaceGui() return; } + SurfaceGui::Workbench::init(); + // instanciating the commands CreateSurfaceCommands(); - SurfaceGui::Workbench::init(); // SurfaceGui::ViewProviderCut::init(); diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 2aad33ec68..2b84ebeccf 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) 2014 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -56,7 +57,7 @@ #include #include - +// Nate's stuff //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -142,9 +143,78 @@ void CmdSurfaceCut::activated(int iMsg) commitCommand();*/ } +// my stuff + +//=========================================================================== +// Surface_Bezier +//=========================================================================== +DEF_STD_CMD_A(CmdSurfaceBezier); + +CmdSurfaceBezier::CmdSurfaceBezier() + :Command("Surface_Bezier") +{ + sAppModule = "Surface"; + sGroup = QT_TR_NOOP("Surface"); + sMenuText = QT_TR_NOOP("Bezier"); + sToolTipText = QT_TR_NOOP("Creates a surface from 2, 3 or 4 Bezier curves"); + sWhatsThis = "Surface_Bezier"; + sStatusTip = sToolTipText; + sPixmap = "BezSurf"; +} + +void CmdSurfaceBezier::activated(int iMsg) +{ + // TODO filter class type + std::vector Sel = getSelection().getSelectionEx(0/*, Part::Feature::getClassTypeId()*/); + + // TODO check if input feature count is between 2 and 4 + /*if (Sel.size() < 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select two shapes or more, please.")); + return; + }*/ + + bool askUser = false; + std::string FeatName = getUniqueObjectName("BezierSurface"); + std::stringstream bezListCmd; + // std::vector tempSelNames; + bezListCmd << "FreeCAD.ActiveDocument.ActiveObject.aBezList = ["; + for (std::vector::iterator it = Sel.begin(); it != Sel.end(); ++it) { + App::DocumentObject* obj = it->getObject(); + // TODO check object types + /*if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + const TopoDS_Shape& shape = static_cast(obj)->Shape.getValue(); + if (!PartGui::checkForSolids(shape) && !askUser) { + int ret = QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Non-solids selected"), + QObject::tr("The use of non-solids for boolean operations may lead to unexpected results.\n" + "Do you want to continue?"), QMessageBox::Yes, QMessageBox::No); + if (ret == QMessageBox::No) + return; + askUser = true; + }*/ + bezListCmd << "FreeCAD.ActiveDocument." << it->getFeatName() << ", "; + // tempSelNames.push_back(it->getFeatName()); + //} + } + bezListCmd << "]"; + + openCommand("Create Bezier surface"); + doCommand(Doc,"FreeCAD.ActiveDocument.addObject(\"Surface::BezSurf\",\"%s\")", FeatName.c_str()); + doCommand(Doc, "FreeCAD.ActiveDocument.ActiveObject.filltype=1"); // TODO ask filltype from user and check it + runCommand(Doc, bezListCmd.str().c_str()); + updateActive(); + commitCommand(); +} + +bool CmdSurfaceBezier::isActive(void) +{ + return true; //TODO check availability getSelection().countObjectsOfType(Part::Feature::getClassTypeId())>=2; +} + void CreateSurfaceCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); rcCmdMgr.addCommand(new CmdSurfaceFilling()); rcCmdMgr.addCommand(new CmdSurfaceCut()); + rcCmdMgr.addCommand(new CmdSurfaceBezier()); } diff --git a/src/Mod/Surface/Gui/Workbench.cpp b/src/Mod/Surface/Gui/Workbench.cpp index 4c50de8c92..9170c1df96 100644 --- a/src/Mod/Surface/Gui/Workbench.cpp +++ b/src/Mod/Surface/Gui/Workbench.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (c) 2014 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -49,15 +50,12 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* root = StdWorkbench::setupMenuBar(); Gui::MenuItem* item = root->findItem( "&Windows" ); - Gui::MenuItem* make = new Gui::MenuItem; - root->insertItem( item, make ); - make->setCommand("MakeSurface"); - *make << "Surface_Filling"; - - Gui::MenuItem* mod = new Gui::MenuItem; - root->insertItem( item, mod ); - mod->setCommand("ModSurface"); - *mod << "Surface_Cut"; + Gui::MenuItem* surface = new Gui::MenuItem; + root->insertItem( item, surface ); + surface->setCommand("Surface"); + *surface << "Surface_Bezier"; + *surface << "Surface_Filling"; + *surface << "Surface_Cut"; return root; } @@ -66,13 +64,11 @@ Gui::ToolBarItem* Workbench::setupToolBars() const { Gui::ToolBarItem* root = StdWorkbench::setupToolBars(); - Gui::ToolBarItem* make = new Gui::ToolBarItem(root); - make->setCommand( "MakeSurface" ); - *make << "Surface_Filling"; - - Gui::ToolBarItem* mod = new Gui::ToolBarItem(root); - mod->setCommand( "ModSurface" ); - *mod << "Surface_Cut"; + Gui::ToolBarItem* surface = new Gui::ToolBarItem(root); + surface->setCommand( "Surface" ); + *surface << "Surface_Bezier"; + *surface << "Surface_Filling"; + *surface << "Surface_Cut"; return root; } diff --git a/src/Mod/Surface/InitGui.py b/src/Mod/Surface/InitGui.py index 283ae17598..9944b2a2af 100644 --- a/src/Mod/Surface/InitGui.py +++ b/src/Mod/Surface/InitGui.py @@ -78,10 +78,20 @@ class SurfaceWorkbench ( Workbench ): # load the module import SurfaceGui import FreeCADGui + import Surface # Set path to icon labels FreeCADGui.addIconPath('./Gui/Resources/Icons/') + def GetClassName(self): return "SurfaceGui::Workbench" + + def Activated(self): + # do something here if needed... + Msg ("SurfaceWorkbench.Activated()\n") + + def Deactivated(self): + # do something here if needed... + Msg ("SurfaceWorkbench.Deactivated()\n") Gui.addWorkbench(SurfaceWorkbench())