1
/***************************************************************************
2
* Copyright (c) 2016 Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <Precision.hxx>
30
#include "FeatureOffset.h"
31
#include <App/Document.h>
36
const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",nullptr};
37
const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",nullptr};
39
PROPERTY_SOURCE(Part::Offset, Part::Feature)
43
ADD_PROPERTY_TYPE(Source,(nullptr),"Offset",App::Prop_None,"Source shape");
44
ADD_PROPERTY_TYPE(Value,(1.0),"Offset",App::Prop_None,"Offset value");
45
ADD_PROPERTY_TYPE(Mode,(long(0)),"Offset",App::Prop_None,"Mode");
46
Mode.setEnums(ModeEnums);
47
ADD_PROPERTY_TYPE(Join,(long(0)),"Offset",App::Prop_None,"Join type");
48
Join.setEnums(JoinEnums);
49
ADD_PROPERTY_TYPE(Intersection,(false),"Offset",App::Prop_None,"Intersection");
50
ADD_PROPERTY_TYPE(SelfIntersection,(false),"Offset",App::Prop_None,"Self Intersection");
51
ADD_PROPERTY_TYPE(Fill,(false),"Offset",App::Prop_None,"Fill offset");
53
Source.setScope(App::LinkScope::Global);
56
Offset::~Offset() = default;
58
short Offset::mustExecute() const
60
if (Source.isTouched())
62
if (Value.isTouched())
68
if (Intersection.isTouched())
70
if (SelfIntersection.isTouched())
77
App::DocumentObjectExecReturn *Offset::execute()
79
App::DocumentObject* source = Source.getValue();
81
return new App::DocumentObjectExecReturn("No source shape linked.");
82
double offset = Value.getValue();
83
double tol = Precision::Confusion();
84
bool inter = Intersection.getValue();
85
bool self = SelfIntersection.getValue();
86
short mode = (short)Mode.getValue();
87
bool fill = Fill.getValue();
88
auto shape = Feature::getTopoShape(source);
90
return new App::DocumentObjectExecReturn("Invalid source link");
91
auto join = static_cast<JoinType>(Join.getValue());
92
this->Shape.setValue(TopoShape(0).makeElementOffset(
93
shape,offset,tol,inter,self,mode,join,fill ? FillType::fill : FillType::noFill));
94
return App::DocumentObject::StdReturn;
98
//-------------------------------------------------------------------------------------------------------
101
PROPERTY_SOURCE(Part::Offset2D, Part::Offset)
105
this->SelfIntersection.setStatus(App::Property::Status::Hidden, true);
106
this->Mode.setValue(1); //switch to Pipe mode by default, because skin mode does not function properly on closed profiles.
109
Offset2D::~Offset2D() = default;
111
short Offset2D::mustExecute() const
113
if (Source.isTouched())
115
if (Value.isTouched())
117
if (Mode.isTouched())
119
if (Join.isTouched())
121
if (Fill.isTouched())
123
if (Intersection.isTouched())
128
App::DocumentObjectExecReturn *Offset2D::execute()
130
App::DocumentObject* source = Source.getValue();
133
return new App::DocumentObjectExecReturn("No source shape linked.");
135
const TopoShape shape = Part::Feature::getTopoShape(source);
136
if (shape.isNull()) {
137
return new App::DocumentObjectExecReturn("No source shape linked.");
139
double offset = Value.getValue();
140
short mode = (short)Mode.getValue();
141
short join = (short)Join.getValue();
142
bool fill = Fill.getValue();
143
bool inter = Intersection.getValue();
145
return new App::DocumentObjectExecReturn("Mode 'Recto-Verso' is not supported for 2D offset.");
147
this->Shape.setValue(shape.makeOffset2D(offset, join, fill, mode == 0, inter));
148
return App::DocumentObject::StdReturn;