FreeCAD

Форк
0
/
FeatureOffset.cpp 
149 строк · 5.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2016 Victor Titov (DeepSOIC) <vv.titov@gmail.com>       *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <Precision.hxx>
26
#endif
27

28
#include <App/Link.h>
29

30
#include "FeatureOffset.h"
31
#include <App/Document.h>
32

33

34
using namespace Part;
35

36
const char* Part::Offset::ModeEnums[]= {"Skin","Pipe", "RectoVerso",nullptr};
37
const char* Part::Offset::JoinEnums[]= {"Arc","Tangent", "Intersection",nullptr};
38

39
PROPERTY_SOURCE(Part::Offset, Part::Feature)
40

41
Offset::Offset()
42
{
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");
52

53
    Source.setScope(App::LinkScope::Global);
54
}
55

56
Offset::~Offset() = default;
57

58
short Offset::mustExecute() const
59
{
60
    if (Source.isTouched())
61
        return 1;
62
    if (Value.isTouched())
63
        return 1;
64
    if (Mode.isTouched())
65
        return 1;
66
    if (Join.isTouched())
67
        return 1;
68
    if (Intersection.isTouched())
69
        return 1;
70
    if (SelfIntersection.isTouched())
71
        return 1;
72
    if (Fill.isTouched())
73
        return 1;
74
    return 0;
75
}
76

77
App::DocumentObjectExecReturn *Offset::execute()
78
{
79
    App::DocumentObject* source = Source.getValue();
80
    if (!source)
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);
89
    if(shape.isNull())
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;
95
}
96

97

98
//-------------------------------------------------------------------------------------------------------
99

100

101
PROPERTY_SOURCE(Part::Offset2D, Part::Offset)
102

103
Offset2D::Offset2D()
104
{
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.
107
}
108

109
Offset2D::~Offset2D() = default;
110

111
short Offset2D::mustExecute() const
112
{
113
    if (Source.isTouched())
114
        return 1;
115
    if (Value.isTouched())
116
        return 1;
117
    if (Mode.isTouched())
118
        return 1;
119
    if (Join.isTouched())
120
        return 1;
121
    if (Fill.isTouched())
122
        return 1;
123
    if (Intersection.isTouched())
124
        return 1;
125
    return 0;
126
}
127

128
App::DocumentObjectExecReturn *Offset2D::execute()
129
{
130
    App::DocumentObject* source = Source.getValue();
131

132
    if (!source) {
133
       return new App::DocumentObjectExecReturn("No source shape linked.");
134
    }
135
    const TopoShape shape = Part::Feature::getTopoShape(source);
136
    if (shape.isNull()) {
137
        return new App::DocumentObjectExecReturn("No source shape linked.");
138
    }
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();
144
    if (mode == 2)
145
        return new App::DocumentObjectExecReturn("Mode 'Recto-Verso' is not supported for 2D offset.");
146

147
    this->Shape.setValue(shape.makeOffset2D(offset, join, fill, mode == 0, inter));
148
    return App::DocumentObject::StdReturn;
149
}
150

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.