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 <kolaloka@freemail.hu>
This commit is contained in:
balazs-bamer
2014-11-20 18:01:59 +01:00
committed by wmayer
parent 6f4e3acce4
commit 4f96fa2300
8 changed files with 145 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* 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 <GeomFill.hxx>
#include <GeomFill_BSplineCurves.hxx>
#include <ShapeFix_Wire.hxx>
@@ -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

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* 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 <GeomFill.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <ShapeFix_Wire.hxx>
@@ -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

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com>,*
* 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();

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* Balázs Bámer *
* *
* This file is part of the FreeCAD CAx development system. *
* *
@@ -56,7 +57,7 @@
#include <App/PropertyUnits.h>
#include <App/PropertyLinks.h>
// 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<Gui::SelectionObject> 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<std::string> tempSelNames;
bezListCmd << "FreeCAD.ActiveDocument.ActiveObject.aBezList = [";
for (std::vector<Gui::SelectionObject>::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<Part::Feature*>(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());
}

View File

@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
* 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;
}

View File

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