Commit 7a177bce authored by Jan Möbius's avatar Jan Möbius
Browse files

Removed accidental commit

parent 10911342
Pipeline #17560 failed with stages
in 1 minute and 39 seconds
include (plugin)
openflipper_plugin ( TYPES TRIANGLEMESH
DIRS Widgets Machine)
#include "Machine.hh"
#include <iostream>
Machine::Machine() :
tcpEnabled_(false),
has_tcp_(false),
has_x_axis_(false),
x_min_(0.0),
x_max_(0.0),
x_pos_(0.0),
has_y_axis_(false),
y_min_(0.0),
y_max_(0.0),
y_pos_(0.0),
has_z_axis_(false),
z_min_(0.0),
z_max_(0.0),
z_pos_(0.0),
has_b_axis_(false),
b_min_(0.0),
b_max_(0.0),
b_pos_(0.0),
has_c_axis_(false),
c_min_(0.0),
c_max_(0.0),
c_pos_(0.0),
sanity_Check_(false)
{
}
void Machine::set_Axis_Configuration(bool _has_x, bool _has_y, bool _has_z , bool _has_b , bool _has_c ) {
has_x_axis_ = _has_x;
has_y_axis_ = _has_y;
has_z_axis_ = _has_z;
has_b_axis_ = _has_b;
has_c_axis_ = _has_c;
}
void Machine::set_X_Boundaries(double _min, double _max) {
x_min_ = _min;
x_max_ = _max;
has_x_axis_ = true;
}
void Machine::set_Y_Boundaries(double _min, double _max) {
y_min_ = _min;
y_max_ = _max;
has_y_axis_ = true;
}
void Machine::set_Z_Boundaries(double _min, double _max) {
z_min_ = _min;
z_max_ = _max;
has_z_axis_ = true;
}
void Machine::set_B_Boundaries(double _min, double _max) {
b_min_ = _min;
b_max_ = _max;
has_b_axis_ = true;
}
void Machine::set_C_Boundaries(double _min, double _max) {
c_min_ = _min;
c_max_ = _max;
has_c_axis_ = true;
}
void Machine::set_TCP_Configuration(bool _has_tcp) {
has_tcp_ = _has_tcp;
}
bool Machine::set_X(double _x) {
if ( sanity_Check_ ) {
if ( _x < x_min_ ) {
error_message_ += " X Axis position out of Range! Minimum is : " + std::to_string(x_min_) + " Value to be set is : " + std::to_string(_x) ;
error_Encountered_ = true;
return false;
}
if ( _x > x_max_ ) {
error_message_ += " X Axis position out of Range! Maximum is : " + std::to_string(x_max_) + " Value to be set is : " + std::to_string(_x) ;
error_Encountered_ = true;
return false;
}
}
x_pos_ = _x;
return true;
}
bool Machine::set_Y(double _y) {
if ( sanity_Check_ ) {
if ( _y < y_min_ ) {
error_message_ += " Y Axis position out of Range! Minimum is : " + std::to_string(y_min_) + " Value to be set is : " + std::to_string(_y) ;
error_Encountered_ = true;
return false;
}
if ( _y > x_max_ ) {
error_message_ += " Y Axis position out of Range! Maximum is : " + std::to_string(y_max_) + " Value to be set is : " + std::to_string(_y) ;
error_Encountered_ = true;
return false;
}
}
y_pos_ = _y;
return true;
}
bool Machine::set_Z(double _z) {
if ( sanity_Check_ ) {
if ( _z < z_min_ ) {
error_message_ += " Z Axis position out of Range! Minimum is : " + std::to_string(z_min_) + " Value to be set is : " + std::to_string(_z) ;
error_Encountered_ = true;
return false;
}
if ( _z > z_max_ ) {
error_message_ += " Z Axis position out of Range! Maximum is : " + std::to_string(z_max_) + " Value to be set is : " + std::to_string(_z) ;
error_Encountered_ = true;
return false;
}
}
z_pos_ = _z;
return true;
}
bool Machine::set_B(double _b) {
if ( sanity_Check_ ) {
if ( _b < b_min_ ) {
error_message_ += " B Axis position out of Range! Minimum is : " + std::to_string(b_min_) + " Value to be set is : " + std::to_string(_b) ;
error_Encountered_ = true;
return false;
}
if ( _b > b_max_ ) {
error_message_ += " B Axis position out of Range! Maximum is : " + std::to_string(b_max_) + " Value to be set is : " + std::to_string(_b) ;
error_Encountered_ = true;
return false;
}
}
b_pos_ = _b;
return true;
}
bool Machine::set_C(double _c) {
if ( sanity_Check_ ) {
if ( _c < c_min_ ) {
error_message_ += " C Axis position out of Range! Minimum is : " + std::to_string(c_min_) + " Value to be set is : " + std::to_string(_c) ;
error_Encountered_ = true;
return false;
}
if ( _c > c_max_ ) {
error_message_ += " C Axis position out of Range! Maximum is : " + std::to_string(c_max_) + " Value to be set is : " + std::to_string(_c) ;
error_Encountered_ = true;
return false;
}
}
c_pos_ = _c;
return true;
}
#pragma once
#include <string>
class Machine {
public:
Machine();
void enable_x_axis();
void set_Axis_Configuration(bool _has_x, bool _has_y, bool _has_z = false , bool _has_b = false , bool _has_c = false);
void set_X_Boundaries(double _min, double _max);
void set_Y_Boundaries(double _min, double _max);
void set_Z_Boundaries(double _min, double _max);
void set_B_Boundaries(double _min, double _max);
void set_C_Boundaries(double _min, double _max);
void set_TCP_Configuration(bool _has_tcp);
bool set_X(double _x);
bool set_Y(double _y);
bool set_Z(double _z);
bool set_C(double _b);
bool set_B(double _c);
void enable_Sanity_Checks();
private:
/** \brief is tool center point management enabled
*
*/
bool tcpEnabled_;
bool has_tcp_;
bool has_x_axis_;
double x_min_;
double x_max_;
double x_pos_;
bool has_y_axis_;
double y_min_;
double y_max_;
double y_pos_;
bool has_z_axis_;
double z_min_;
double z_max_;
double z_pos_;
bool has_b_axis_;
double b_min_;
double b_max_;
double b_pos_;
bool has_c_axis_;
double c_min_;
double c_max_;
double c_pos_;
bool sanity_Check_;
bool error_Encountered_;
std::string error_message_;
};
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include <MillingSimulatorPlugin.hh>
#include <QFileDialog>
//#include <QInputDialog>
//#include <QtXml/QXmlSimpleReader>
//#include <QtXml/QDomDocument>
//#include "MillingSimulatorPlugin.hh"
//#include <MachineProvider.h>
//#include "MachineJsonParser.hh"
//#include "Plugin-TypeTriangleMesh/TriMeshBackup.hh"
//#include "GCodeSimulator.hh"
//#include <parserlib/parser.h>
//
//using namespace std;
//using namespace gpr;
//------------------------------------------------------------------------------
/** \brief Constructor
*
*/
MillingSimulatorPlugin::MillingSimulatorPlugin():
toolbox_(nullptr)
{
}
//------------------------------------------------------------------------------
QString MillingSimulatorPlugin::name() {
return "MillingSimulator";
}
//------------------------------------------------------------------------------
QString MillingSimulatorPlugin::description() {
return "Plugin to Simulate CNC Machines using G-Code";
}
void MillingSimulatorPlugin::initializePlugin() {
toolbox_ = new MillingPluginToolbox();
connect( toolbox_->machineLoadButton, SIGNAL(clicked()), this, SLOT(openMachineFileDialog()));
connect( toolbox_->pbPlay, SIGNAL(clicked()), this, SLOT(play()));
connect( toolbox_->pbNextFrame, SIGNAL(clicked()), this, SLOT(nextStep()));
connect( toolbox_->gcodeloadbutton, SIGNAL(clicked()), this, SLOT(openGCodeFileDialog()));
connect( toolbox_->xAxisSpinBox, SIGNAL(valueChanged ( double )), this, SLOT( setXAxis(double)));
connect( toolbox_->yAxisSpinBox, SIGNAL(valueChanged ( double )), this, SLOT( setYAxis(double)));
connect( toolbox_->zAxisSpinBox, SIGNAL(valueChanged ( double )), this, SLOT( setZAxis(double)));
connect( toolbox_->bAxisSpinBox, SIGNAL(valueChanged ( double )), this, SLOT( setBAxis(double)));
connect( toolbox_->wAxisSpinBox, SIGNAL(valueChanged ( double )), this, SLOT( setCAxis(double)));
emit addToolbox(tr("Milling Simulator"),toolbox_);
}
void MillingSimulatorPlugin::openMachineFileDialog()
{
toolbox_->machineTextEdit->setPlainText(QFileDialog::getOpenFileName(toolbox_, tr("Open Machine Specification"), "", tr("( *.xml)")));
// initializeMachine(toolBox->machineTextEdit->toPlainText());
}
void MillingSimulatorPlugin::play()
{
// if(simulator == nullptr)
// simulator = new GCodeSimulator(*machine, *gcode);
// simulator->simulate();
}
void MillingSimulatorPlugin::stop()
{
}
void MillingSimulatorPlugin::nextStep()
{
// if (simulator == nullptr) {
//
// simulator = new GCodeSimulator(*machine, *gcode);
// }
// simulator->simulateSingleStep();
}
void MillingSimulatorPlugin::openGCodeFileDialog()
{
auto filePath = QFileDialog::getOpenFileName(toolbox_, tr("Open GCode File"), "", tr("(*.gcode *.cnc)"));
// toolBox->gcodeTextEdit->setPlainText(filePath);
//
// QFile jsonFile(toolBox->gcodeTextEdit->toPlainText());
//
// //try open file
// if (!jsonFile.open(QIODevice::ReadOnly))
// {
// throw jsonFile.error();;
// }
// gcode = new gcode_program(parse_gcode(jsonFile.readAll().toStdString()));
}
void MillingSimulatorPlugin::setXAxis(double value) {
// const auto delta = value - x;
// x = value;
// machine->translate(QVector3D(delta, 0, 0));
// updateModelMatrices();
}
void MillingSimulatorPlugin::setYAxis(double value) {
// const auto delta = value - y;
// y = value;
// machine->translate(QVector3D(0, delta, 0));
// updateModelMatrices();
}
void MillingSimulatorPlugin::setZAxis(double value) {
// const auto delta = value - z;
// z = value;
// machine->translate(QVector3D(0, 0, delta));
// updateModelMatrices();
}
void MillingSimulatorPlugin::setBAxis(double value) {
// const auto delta = value - b;
// b = value;
// updateModelMatrices();
}
void MillingSimulatorPlugin::setCAxis(double value) {
// const auto delta = value - c;
// c = value;
// updateModelMatrices();
}
//
//void MillingSimulatorPlugin::loadMachineMeshes(Machine* machine, QString basePath)
//{
// if (machine == nullptr)
// return;
// if(toolBox == nullptr || toolBox->machineTextEdit == nullptr)
// return;
//
// ///dfs over machine parts
// QStack<Part*> stack;
// stack.push_back(machine->root);
// while(!stack.isEmpty()) {
// auto item = stack.pop();
// emit load(basePath + item->meshObjectPath,typeId("TriangleMesh"), item->objectId);
// for(auto child : item->subparts)
// stack.push_back(child);
// }
//}
//
//void MillingSimulatorPlugin::initializeMachine(QString machineSpecificationPath) {
// MachineProvider* provider = new MachineJsonParser(machineSpecificationPath);
// machine = provider->GetMachine();
// machine->translationConstant = 1/(double)10;
// machine->setParent(this);
// // machine->onChanged = [this](){updateModelMatrices();};
// connect(machine, SIGNAL(changed()), this, SLOT(updateModelMatrices()));
// // QTimer* testTimer = new QTimer(this);
// // connect(testTimer, SIGNAL(timeout()), this, SLOT(updateModelMatrices()));
// // testTimer->start(500);
// //get directory to machine file
// auto filePath = toolBox->machineTextEdit->toPlainText();
// auto index = filePath.lastIndexOf(QChar('/'));
// loadMachineMeshes(machine, filePath.left(index));
// emit updateView();
//}
//
//void MillingSimulatorPlugin::updateModelMatrices()
//{
// ///dfs over machine parts
// QStack<Part*> stack;
// stack.push_back(machine->root);
// while (!stack.isEmpty()) {
// auto part = stack.pop();
//
// auto mesh = PluginFunctions::triMeshObject(part->objectId);
// auto translation = part->getTranslation() * machine->translationConstant;
// mesh->manipulatorNode()->setTranslation(ACG::Vec3d(static_cast<double>(translation.x()), static_cast<double>(translation.y()), static_cast<double>(translation.z())));
// emit updateView();
// for (auto child : part->subparts)
// stack.push_back(child);
// }
// emit updateView();
//}
//
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
\*===========================================================================*/
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include "Widgets/MillingPluginToolbox.hh"
#include <OpenFlipper/common/Types.hh>
class MillingSimulatorPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, LoadSaveInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(ToolboxInterface)
Q_INTERFACES(LoggingInterface)
Q_INTERFACES(LoadSaveInterface)
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.MillingSimulator")
signals:
void updateView();
void updatedObject(int _identifier, const UpdateType& _type);
//LoggingInterface
void log(Logtype _type, QString _message);
void log(QString _message);
// ToolboxInterface
void addToolbox( QString _name, QWidget* _widget );
//LoadSaveInterface
void save (int _id, QString _filename);
void load (QString _filename, DataType _type, int &_id);
public:
MillingSimulatorPlugin();
//BaseInterface
QString name() override;
QString description() override;
public slots:
void openMachineFileDialog();
void openGCodeFileDialog();
void setXAxis(double value);
void setYAxis(double value);
void setZAxis(double value);
void setBAxis(double value);
void setCAxis(double value);
private slots:
void initializePlugin() override;
void play();
void stop();
void nextStep();
private: