File size: 4,847 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
 *   Copyright (c) 2014 Yorik van Havre <yorik@uncreated.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                                *
 *                                                                         *
 ***************************************************************************/

#ifndef PATH_Path_H
#define PATH_Path_H

#include <Base/BoundBox.h>
#include <Base/Persistence.h>
#include <Base/Vector3D.h>

#include "Command.h"


namespace Path
{

/** The representation of a CNC Toolpath */

class PathExport Toolpath: public Base::Persistence
{
    TYPESYSTEM_HEADER_WITH_OVERRIDE();

public:
    Toolpath();
    Toolpath(const Toolpath&);
    ~Toolpath() override;

    Toolpath& operator=(const Toolpath&);

    // from base class
    unsigned int getMemSize() const override;
    void Save(Base::Writer& /*writer*/) const override;
    void Restore(Base::XMLReader& /*reader*/) override;
    void SaveDocFile(Base::Writer& writer) const override;
    void RestoreDocFile(Base::Reader& reader) override;

    // interface
    void clear();                                         // clears the internal data
    void addCommand(const Command& Cmd);                  // adds a command at the end
    void addCommandNoRecalc(const Command& Cmd);          // adds a command without recalculation
    void insertCommand(const Command& Cmd, int);          // inserts a command
    void deleteCommand(int);                              // deletes a command
    double getLength();                                   // return the Length (mm) of the Path
    double getCycleTime(double, double, double, double);  // return the Cycle Time (s) of the Path
    void recalculate();                                   // recalculates the points
    void setFromGCode(const std::string);  // sets the path from the contents of the given GCode string
    std::string toGCode() const;           // gets a gcode string representation from the Path
    Base::BoundBox3d getBoundBox() const;

    // shortcut functions
    unsigned int getSize() const
    {
        return vpcCommands.size();
    }
    const std::vector<Command*>& getCommands() const
    {
        return vpcCommands;
    }
    const Command& getCommand(unsigned int pos) const
    {
        return *vpcCommands[pos];
    }

    // support for rotation
    const Base::Vector3d& getCenter() const
    {
        return center;
    }
    void setCenter(const Base::Vector3d& c);

    static const int SchemaVersion = 2;

protected:
    std::vector<Command*> vpcCommands;
    Base::Vector3d center;
    // KDL::Path_Composite *pcPath;

    /*
    inline  KDL::Frame toFrame(const Base::Placement &To){
        return KDL::Frame(KDL::Rotation::Quaternion(To.getRotation()[0],
                                                    To.getRotation()[1],
                                                    To.getRotation()[2],
                                                    To.getRotation()[3]),
                                                    KDL::Vector(To.getPosition()[0],
                                                    To.getPosition()[1],
                                                    To.getPosition()[2]));
    }
    inline  Base::Placement toPlacement(const KDL::Frame &To){
        double x,y,z,w;
        To.M.GetQuaternion(x,y,z,w);
        return Base::Placement(Base::Vector3d(To.p[0],To.p[1],To.p[2]),Base::Rotation(x,y,z,w));
    } */
};

}  // namespace Path


#endif  // PATH_Path_H