<commit_before>/***************************************************************************
 *   Copyright (c) 2014-2015 <NAME>    <Nathan.A.Mill[at]gmail.com> *
 *                           <NAME>                                  *
 *                                                                         *
 *   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 <ShapeFix_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#endif

#include <Base/Exception.h>
#include <Base/Tools.h>

#include "FeatureSurface.h"

using namespace Surface;

ShapeValidator::ShapeValidator()
{
   initValidator();
}

void ShapeValidator::initValidator(void)
{
    willBezier = willBSpline = false;
    edgeCount = 0;
}

// shows error message if the shape is not an edge
void ShapeValidator::checkEdge(const TopoDS_Shape& shape)
{
    if (shape.IsNull() || shape.ShapeType() != TopAbs_EDGE) {
        Standard_Failure::Raise("Shape is not an edge.");
    }

    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 bez_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve
    Handle_Geom_BSplineCurve bsp_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve

    if (!bez_geom.IsNull()) {
        // this one is a Bezier
        if (willBSpline) {
            // already found the other type, fail
            Standard_Failure::Raise("Mixing Bezier and B-Spline curves is not allowed.");
        }
        // we will create Bezier surface
        willBezier = true;
    }
    else if (!bsp_geom.IsNull()) {
        // this one is Bezier
        if (willBezier) {
            // already found the other type, fail
            Standard_Failure::Raise("Mixing Bezier and B-Spline curves is not allowed.");
        }
        // we will create B-Spline surface
        willBSpline = true;
    }
    else {
        //Standard_Failure::Raise("Neither Bezier nor B-Spline curve.");
    }

    edgeCount++;
}

void ShapeValidator::checkAndAdd(const TopoDS_Shape &shape, Handle(ShapeExtend_WireData) *aWD)
{
    checkEdge(shape);
    if (aWD != NULL) {
        BRepBuilderAPI_Copy copier(shape);
        // make a copy of the shape and the underlying geometry to avoid to affect the input shapes
        (*aWD)->Add(TopoDS::Edge(copier.Shape()));
    }
}

void ShapeValidator::checkAndAdd(const Part::TopoShape &ts, const char *subName, Handle(ShapeExtend_WireData) *aWD)
{
    try {
#if 0 // weird logic!
        // unwrap the wire
        if ((!ts._Shape.IsNull()) && ts._Shape.ShapeType() == TopAbs_WIRE) {
            TopoDS_Wire wire = TopoDS::Wire(ts._Shape);
            for (TopExp_Explorer wireExplorer (wire, TopAbs_EDGE); wireExplorer.More(); wireExplorer.Next()) {
                checkAndAdd(wireExplorer.Current(), aWD);
            }
        }
        else {
            if (subName != NULL && *subName != 0) {
                //we want only the subshape which is linked
                checkAndAdd(ts.getSubShape(subName), aWD);
            }
            else {
                checkAndAdd(ts._Shape, aWD);
            }
        }
#else
        if (subName != NULL && *subName != '\0') {
            //we want only the subshape which is linked
            checkAndAdd(ts.getSubShape(subName), aWD);
        }
        else if (!ts.getShape().IsNull() && ts.getShape().ShapeType() == TopAbs_WIRE) {
            TopoDS_Wire wire = TopoDS::Wire(ts.getShape());
            for (TopExp_Explorer xp(wire, TopAbs_EDGE); xp.More(); xp.Next()) {
                checkAndAdd(xp.Current(), aWD);
            }
        }
        else {
            checkAndAdd(ts.getShape(), aWD);
        }
#endif
    }
    catch(Standard_Failure) { // any OCC exception means an unappropriate shape in the selection
        Standard_Failure::Raise("Wrong shape type.");
    }
}


PROPERTY_SOURCE(Surface::SurfaceFeature, Part::Feature)

const char* SurfaceFeature::FillTypeEnums[]    = {"Invalid", "Stretched", "Coons", "Curved", NULL};

SurfaceFeature::SurfaceFeature(): Feature()
{
    ADD_PROPERTY(FillType, ((long)0));
    ADD_PROPERTY(BoundaryList, (0, "Dummy"));
    FillType.setStatus(App::Property::ReadOnly, true); // read-only in property editor
    FillType.setEnums(FillTypeEnums);
}


//Check if any components of the surface have been modified
short SurfaceFeature::mustExecute() const
{
    if (BoundaryList.isTouched() ||
        FillType.isTouched())
    {
        return 1;
    }
    return 0;
}

GeomFill_FillingStyle SurfaceFeature::getFillingStyle()
{
    //Identify filling style
    int ftype = FillType.getValue();
    if (ftype==StretchStyle)
        return GeomFill_StretchStyle;
    else if(ftype==CoonsStyle)
        return GeomFill_CoonsStyle;
    else if(ftype==CurvedStyle)
        return GeomFill_CurvedStyle;
    else
        Standard_Failure::Raise("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");
    throw; // this is to shut up the compiler
}

<commit_msg>do not make property read-only in property editor<commit_after>/***************************************************************************
 *   Copyright (c) 2014-2015 <NAME>    <Nathan.A.Mill[at]gmail.com> *
 *                           <NAME>                                  *
 *                                                                         *
 *   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 <ShapeFix_Wire.hxx>
#include <ShapeExtend_WireData.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <GeomFill_BezierCurves.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#endif

#include <Base/Exception.h>
#include <Base/Tools.h>

#include "FeatureSurface.h"

using namespace Surface;

ShapeValidator::ShapeValidator()
{
   initValidator();
}

void ShapeValidator::initValidator(void)
{
    willBezier = willBSpline = false;
    edgeCount = 0;
}

// shows error message if the shape is not an edge
void ShapeValidator::checkEdge(const TopoDS_Shape& shape)
{
    if (shape.IsNull() || shape.ShapeType() != TopAbs_EDGE) {
        Standard_Failure::Raise("Shape is not an edge.");
    }

    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 bez_geom = Handle_Geom_BezierCurve::DownCast(c_geom); //Try to get Bezier curve
    Handle_Geom_BSplineCurve bsp_geom = Handle_Geom_BSplineCurve::DownCast(c_geom); //Try to get BSpline curve

    if (!bez_geom.IsNull()) {
        // this one is a Bezier
        if (willBSpline) {
            // already found the other type, fail
            Standard_Failure::Raise("Mixing Bezier and B-Spline curves is not allowed.");
        }
        // we will create Bezier surface
        willBezier = true;
    }
    else if (!bsp_geom.IsNull()) {
        // this one is Bezier
        if (willBezier) {
            // already found the other type, fail
            Standard_Failure::Raise("Mixing Bezier and B-Spline curves is not allowed.");
        }
        // we will create B-Spline surface
        willBSpline = true;
    }
    else {
        //Standard_Failure::Raise("Neither Bezier nor B-Spline curve.");
    }

    edgeCount++;
}

void ShapeValidator::checkAndAdd(const TopoDS_Shape &shape, Handle(ShapeExtend_WireData) *aWD)
{
    checkEdge(shape);
    if (aWD != NULL) {
        BRepBuilderAPI_Copy copier(shape);
        // make a copy of the shape and the underlying geometry to avoid to affect the input shapes
        (*aWD)->Add(TopoDS::Edge(copier.Shape()));
    }
}

void ShapeValidator::checkAndAdd(const Part::TopoShape &ts, const char *subName, Handle(ShapeExtend_WireData) *aWD)
{
    try {
#if 0 // weird logic!
        // unwrap the wire
        if ((!ts._Shape.IsNull()) && ts._Shape.ShapeType() == TopAbs_WIRE) {
            TopoDS_Wire wire = TopoDS::Wire(ts._Shape);
            for (TopExp_Explorer wireExplorer (wire, TopAbs_EDGE); wireExplorer.More(); wireExplorer.Next()) {
                checkAndAdd(wireExplorer.Current(), aWD);
            }
        }
        else {
            if (subName != NULL && *subName != 0) {
                //we want only the subshape which is linked
                checkAndAdd(ts.getSubShape(subName), aWD);
            }
            else {
                checkAndAdd(ts._Shape, aWD);
            }
        }
#else
        if (subName != NULL && *subName != '\0') {
            //we want only the subshape which is linked
            checkAndAdd(ts.getSubShape(subName), aWD);
        }
        else if (!ts.getShape().IsNull() && ts.getShape().ShapeType() == TopAbs_WIRE) {
            TopoDS_Wire wire = TopoDS::Wire(ts.getShape());
            for (TopExp_Explorer xp(wire, TopAbs_EDGE); xp.More(); xp.Next()) {
                checkAndAdd(xp.Current(), aWD);
            }
        }
        else {
            checkAndAdd(ts.getShape(), aWD);
        }
#endif
    }
    catch(Standard_Failure) { // any OCC exception means an unappropriate shape in the selection
        Standard_Failure::Raise("Wrong shape type.");
    }
}


PROPERTY_SOURCE(Surface::SurfaceFeature, Part::Feature)

const char* SurfaceFeature::FillTypeEnums[]    = {"Invalid", "Stretched", "Coons", "Curved", NULL};

SurfaceFeature::SurfaceFeature(): Feature()
{
    ADD_PROPERTY(FillType, ((long)0));
    ADD_PROPERTY(BoundaryList, (0, "Dummy"));
    FillType.setEnums(FillTypeEnums);
}


//Check if any components of the surface have been modified
short SurfaceFeature::mustExecute() const
{
    if (BoundaryList.isTouched() ||
        FillType.isTouched())
    {
        return 1;
    }
    return 0;
}

GeomFill_FillingStyle SurfaceFeature::getFillingStyle()
{
    //Identify filling style
    int ftype = FillType.getValue();
    if (ftype==StretchStyle)
        return GeomFill_StretchStyle;
    else if(ftype==CoonsStyle)
        return GeomFill_CoonsStyle;
    else if(ftype==CurvedStyle)
        return GeomFill_CurvedStyle;
    else
        Standard_Failure::Raise("Filling style must be 1 (Stretch), 2 (Coons), or 3 (Curved).");
    throw; // this is to shut up the compiler
}


{'fraction_non_alphanumeric': 0.12371359754762426, 'fraction_numerical': 0.005547040362017371, 'mean_word_length': 2.217942696101456, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '3001536', 'n_tokens_mistral': 4069, 'n_tokens_neox': 3924, 'n_words': 1063}