From 37406a968eb044a6c8377cf0dfc2abbd57429ab6 Mon Sep 17 00:00:00 2001 From: balazs-bamer Date: Sat, 3 Jan 2015 19:39:10 +0100 Subject: [PATCH] Bezier surface: check selected objects As the GUI selection changes, the Bezier surface tool avaibility is always updated, so it is active if and only if 2-4 Bezier curves are selected. --- src/Mod/Surface/App/FeatureBSurf.cpp | 4 +- src/Mod/Surface/App/FeatureBSurf.h | 3 +- src/Mod/Surface/App/FeatureBezSurf.cpp | 5 +- src/Mod/Surface/App/FeatureBezSurf.h | 3 +- src/Mod/Surface/Gui/Command.cpp | 93 ++++++++++++++------------ 5 files changed, 60 insertions(+), 48 deletions(-) diff --git a/src/Mod/Surface/App/FeatureBSurf.cpp b/src/Mod/Surface/App/FeatureBSurf.cpp index 4a86082225..3894bf7558 100644 --- a/src/Mod/Surface/App/FeatureBSurf.cpp +++ b/src/Mod/Surface/App/FeatureBSurf.cpp @@ -1,6 +1,6 @@ - /*************************************************************************** - * Copyright (c) 2014 Balázs Bámer * + * Copyright (c) 2014-2015 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Surface/App/FeatureBSurf.h b/src/Mod/Surface/App/FeatureBSurf.h index b6d5831dc6..e14f67df9e 100644 --- a/src/Mod/Surface/App/FeatureBSurf.h +++ b/src/Mod/Surface/App/FeatureBSurf.h @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (c) 2014 Balázs Bámer * + * Copyright (c) 2014-2015 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Surface/App/FeatureBezSurf.cpp b/src/Mod/Surface/App/FeatureBezSurf.cpp index f9e3b20a1e..9ec16d207f 100644 --- a/src/Mod/Surface/App/FeatureBezSurf.cpp +++ b/src/Mod/Surface/App/FeatureBezSurf.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (c) 2014 Nathan Miller * - * Balázs Bámer * + * Copyright (c) 2014-2015 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -54,7 +54,6 @@ BezSurf::BezSurf() { ADD_PROPERTY(aBList,(0,"Geom_BezierCurve")); ADD_PROPERTY(filltype,(1)); - } //Structures diff --git a/src/Mod/Surface/App/FeatureBezSurf.h b/src/Mod/Surface/App/FeatureBezSurf.h index 9ff8e2ca4e..f0bbcd8e46 100644 --- a/src/Mod/Surface/App/FeatureBezSurf.h +++ b/src/Mod/Surface/App/FeatureBezSurf.h @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright (c) 2014 Nathan Miller * + * Copyright (c) 2014-2015 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 3ca9a7b7fd..31368a122a 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (c) 2014 Nathan Miller * - * Balázs Bámer * + * Copyright (c) 2014-2015 Nathan Miller * + * Balázs Bámer * * * * This file is part of the FreeCAD CAx development system. * * * @@ -24,23 +24,24 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include #include -//#include -//#include - #include #include #include @@ -56,6 +57,7 @@ #include #include #include +#include "Mod/Part/App/PartFeature.h" // Nate's stuff @@ -143,7 +145,6 @@ void CmdSurfaceCut::activated(int iMsg) commitCommand();*/ } -// my stuff //=========================================================================== // Surface_Bezier @@ -164,37 +165,19 @@ CmdSurfaceBezier::CmdSurfaceBezier() 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) { + /*if (!isActive()) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select two shapes or more, please.")); + QObject::tr("Select 2, 3 or 4 curves, please.")); return; }*/ - bool askUser = false; + // 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; - // std::vector tempSelNames; bezListCmd << "FreeCAD.ActiveDocument.ActiveObject.aBList = ["; - 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 << "(App.activeDocument()." << it->getFeatName() << ", \'Edge1\'),"; - // tempSelNames.push_back(it->getFeatName()); - //} + for (std::vector::iterator it = Selo.begin(); it != Selo.end(); ++it) { + bezListCmd << "(App.activeDocument()." << it->getFeatName() << ", \'Edge1\'),"; } bezListCmd << "]"; @@ -208,7 +191,35 @@ void CmdSurfaceBezier::activated(int iMsg) bool CmdSurfaceBezier::isActive(void) { - return true; //TODO check availability getSelection().countObjectsOfType(Part::Feature::getClassTypeId())>=2; + std::vector Sel = getSelection().getSelection(); + if (Sel.size() < 2 || Sel.size() > 4) { + return false; + } + for (std::vector::iterator it = Sel.begin(); it != Sel.end(); ++it) + { + if(!((*it).pObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))) { + return false; + } + Part::TopoShape ts = static_cast((*it).pObject)->Shape.getShape(); + TopoDS_Shape shape = ts.getSubShape("Edge1"); + if (shape.IsNull()) + { + return false; + } + if(shape.ShapeType() != TopAbs_EDGE) { //Check Shape type and assign edge + return false; + } + TopoDS_Edge etmp = TopoDS::Edge(shape); //Curve TopoDS_Edge + TopLoc_Location heloc; // this will be output + Standard_Real u0;// contains output + Standard_Real u1;// contains output + Handle_Geom_Curve c_geom = BRep_Tool::Curve(etmp,heloc,u0,u1); //The geometric curve + Handle_Geom_BezierCurve b_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve + if (b_geom.IsNull()) { + return false; + } + } + return true; } void CreateSurfaceCommands(void)