<commit_before>/***************************************************************************
 *   Copyright (c) 2012 <NAME> <jrheinlaender[at]users.sourceforge.net>     *
 *                                                                         *
 *   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                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepOffsetAPI_DraftAngle.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx>
# include <gp_Ax1.hxx>
//# include <BRepAdaptor_CompCurve.hxx>
# include <gp_Pln.hxx>
# include <gp_Lin.hxx>
# include <gp_Dir.hxx>
# include <gp_Circ.hxx>
# include <GeomAbs_SurfaceType.hxx>
# include <GeomAPI_IntSS.hxx>
# include <Geom_Plane.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Line.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
#endif

#include <Mod/Part/App/TopoShape.h>

#include "FeatureDraft.h"


using namespace PartDesign;

#include <Base/Console.h>


PROPERTY_SOURCE(PartDesign::Draft, PartDesign::DressUp)

const App::PropertyFloatConstraint::Constraints floatAngle = {0.0f,89.99f,0.1f};

Draft::Draft()
{
    ADD_PROPERTY(Angle,(1.5f));
    Angle.setConstraints(&floatAngle);
    ADD_PROPERTY_TYPE(NeutralPlane,(0),"Draft",(App::PropertyType)(App::Prop_None),"NeutralPlane");
    ADD_PROPERTY_TYPE(PullDirection,(0),"Draft",(App::PropertyType)(App::Prop_None),"PullDirection");
    ADD_PROPERTY(Reversed,(0));
}

short Draft::mustExecute() const
{
    if (Placement.isTouched() ||
        Angle.isTouched() ||
        NeutralPlane.isTouched() ||
        PullDirection.isTouched() ||
        Reversed.isTouched())
        return 1;
    return DressUp::mustExecute();
}

App::DocumentObjectExecReturn *Draft::execute(void)
{
    // Get parameters
    // Base shape
    App::DocumentObject* link = Base.getValue();
    if (!link)
        return new App::DocumentObjectExecReturn("No object linked");
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
    Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
    const Part::TopoShape& TopShape = base->Shape.getShape();
    if (TopShape._Shape.IsNull())
        return new App::DocumentObjectExecReturn("Cannot draft invalid shape");

    // Faces where draft should be applied
    const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Face");
    if (SubVals.size() == 0)
        return new App::DocumentObjectExecReturn("No faces specified");

    // Draft angle
    float angle = Angle.getValue();
    if ((angle < 0.0) || (angle >= 90.0))
        return new App::DocumentObjectExecReturn("Draft angle must be between 0 and 90 degrees");
    angle = angle / 180.0 * M_PI;

    // Pull direction
    gp_Dir pullDirection;
    App::DocumentObject* refDirection = PullDirection.getValue();
    if (refDirection != NULL) {
        if (!refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
            throw Base::Exception("Pull direction reference must be an edge of a feature");
        std::vector<std::string> subStrings = PullDirection.getSubValues();
        if (subStrings.empty() || subStrings[0].empty())
            throw Base::Exception("No pull direction reference specified");

        Part::Feature* refFeature = static_cast<Part::Feature*>(refDirection);
        Part::TopoShape refShape = refFeature->Shape.getShape();
        TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());

        if (ref.ShapeType() == TopAbs_EDGE) {
            TopoDS_Edge refEdge = TopoDS::Edge(ref);
            if (refEdge.IsNull())
                throw Base::Exception("Failed to extract pull direction reference edge");
            BRepAdaptor_Curve adapt(refEdge);
            if (adapt.GetType() != GeomAbs_Line)<commit_msg>Removed unnecessary boundary check for FloatConstraint property<commit_after>/***************************************************************************
 *   Copyright (c) 2012 <NAME> <jrheinlaender[at]users.sourceforge.net>     *
 *                                                                         *
 *   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                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepOffsetAPI_DraftAngle.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Face.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <gp_Dir.hxx>
# include <gp_Pln.hxx>
# include <gp_Ax1.hxx>
//# include <BRepAdaptor_CompCurve.hxx>
# include <gp_Pln.hxx>
# include <gp_Lin.hxx>
# include <gp_Dir.hxx>
# include <gp_Circ.hxx>
# include <GeomAbs_SurfaceType.hxx>
# include <GeomAPI_IntSS.hxx>
# include <Geom_Plane.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Line.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
#endif

#include <Mod/Part/App/TopoShape.h>

#include "FeatureDraft.h"


using namespace PartDesign;

#include <Base/Console.h>


PROPERTY_SOURCE(PartDesign::Draft, PartDesign::DressUp)

const App::PropertyFloatConstraint::Constraints floatAngle = {0.0f,89.99f,0.1f};

Draft::Draft()
{
    ADD_PROPERTY(Angle,(1.5f));
    Angle.setConstraints(&floatAngle);
    ADD_PROPERTY_TYPE(NeutralPlane,(0),"Draft",(App::PropertyType)(App::Prop_None),"NeutralPlane");
    ADD_PROPERTY_TYPE(PullDirection,(0),"Draft",(App::PropertyType)(App::Prop_None),"PullDirection");
    ADD_PROPERTY(Reversed,(0));
}

short Draft::mustExecute() const
{
    if (Placement.isTouched() ||
        Angle.isTouched() ||
        NeutralPlane.isTouched() ||
        PullDirection.isTouched() ||
        Reversed.isTouched())
        return 1;
    return DressUp::mustExecute();
}

App::DocumentObjectExecReturn *Draft::execute(void)
{
    // Get parameters
    // Base shape
    App::DocumentObject* link = Base.getValue();
    if (!link)
        return new App::DocumentObjectExecReturn("No object linked");
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
    Part::Feature *base = static_cast<Part::Feature*>(Base.getValue());
    const Part::TopoShape& TopShape = base->Shape.getShape();
    if (TopShape._Shape.IsNull())
        return new App::DocumentObjectExecReturn("Cannot draft invalid shape");

    // Faces where draft should be applied
    const std::vector<std::string>& SubVals = Base.getSubValuesStartsWith("Face");
    if (SubVals.size() == 0)
        return new App::DocumentObjectExecReturn("No faces specified");

    // Draft angle
    float angle = Angle.getValue() / 180.0 * M_PI;

    // Pull direction
    gp_Dir pullDirection;
    App::DocumentObject* refDirection = PullDirection.getValue();
    if (refDirection != NULL) {
        if (!refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
            throw Base::Exception("Pull direction reference must be an edge of a feature");
        std::vector<std::string> subStrings = PullDirection.getSubValues();
        if (subStrings.empty() || subStrings[0].empty())
            throw Base::Exception("No pull direction reference specified");

        Part::Feature* refFeature = static_cast<Part::Feature*>(refDirection);
        Part::TopoShape refShape = refFeature->Shape.getShape();
        TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());

        if (ref.ShapeType() == TopAbs_EDGE) {
            TopoDS_Edge refEdge = TopoDS::Edge(ref);
            if (refEdge.IsNull())
                throw Base::Exception("Failed to extract pull direction reference edge");
            BRepAdaptor_Curve adapt(refEdge);
            if (adapt.GetType() != GeomAbs_Line)
{'fraction_non_alphanumeric': 0.13977176270866737, 'fraction_numerical': 0.008488163727247006, 'mean_word_length': 2.6986396930589467, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7377679', 'n_tokens_mistral': 3038, 'n_tokens_neox': 2930, 'n_words': 725}