This commit is contained in:
Chenwenxuan
2024-03-06 14:54:30 +08:00
commit edac2715f0
1525 changed files with 809982 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include "qc_actiongetent.h"
#include <QMouseEvent>
#include <QKeyEvent>
#include "doc_plugin_interface.h"
#include "rs_dialogfactory.h"
#include "rs_selection.h"
#include "rs_snapper.h"
#include "rs_debug.h"
// #include <QDebug>
QC_ActionGetEnt::QC_ActionGetEnt(RS_EntityContainer& container,
RS_GraphicView& graphicView)
:RS_ActionInterface("Get Entity", container, graphicView) {
completed = false;
message = tr("Select object:");
en = nullptr;
}
void QC_ActionGetEnt::updateMouseButtonHints() {
if (!completed)
RS_DIALOGFACTORY->updateMouseWidget(message, tr("Cancel"));
else
RS_DIALOGFACTORY->updateMouseWidget();
}
void QC_ActionGetEnt::updateMouseCursor() {
graphicView->setMouseCursor(RS2::SelectCursor);
}
void QC_ActionGetEnt::setMessage(QString msg){
message = msg;
}
void QC_ActionGetEnt::trigger() {
if (en) {
RS_Selection s(*container, graphicView);
s.selectSingle(en);
completed = true;
updateMouseButtonHints();
} else {
RS_DEBUG->print("QC_ActionGetEnt::trigger: Entity is NULL\n");
}
}
void QC_ActionGetEnt::mouseReleaseEvent(QMouseEvent* e) {
if (e->button()==Qt::RightButton) {
completed = true;
updateMouseButtonHints();
finish();
} else {
en = catchEntity(e);
trigger();
}
}
void QC_ActionGetEnt::keyPressEvent(QKeyEvent* e)
{
// qDebug() << "QC_ActionGetEnt::keyPressEvent";
if (e->key()==Qt::Key_Escape)
{
RS_DIALOGFACTORY->updateMouseWidget();
completed = true;
// qDebug() << "escape QC_ActionGetEnt";
}
}
/**
* Add selected entity from 'container' to the selection.
*/
Plugin_Entity *QC_ActionGetEnt::getSelected(Doc_plugin_interface* d) {
Plugin_Entity *pe = en ? new Plugin_Entity(en, d) : nullptr;
return pe;
}
// EOF

View File

@@ -0,0 +1,82 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef QC_ACTIONGETENT_H
#define QC_ACTIONGETENT_H
#include "rs_previewactioninterface.h"
#include "rs_modification.h"
class Plugin_Entity;
class Doc_plugin_interface;
/**
* This action class can handle user events to select entities from plugin.
*
* @author Rallaz
*/
class QC_ActionGetEnt : public RS_ActionInterface {
Q_OBJECT
//public:
/**
* Action States.
*/
/* enum Status {
Select
};*/
public:
QC_ActionGetEnt(RS_EntityContainer& container,
RS_GraphicView& graphicView);
~QC_ActionGetEnt() {}
virtual void updateMouseButtonHints();
/* virtual void init(int status=0);
virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void updateMouseCursor();
virtual void updateToolBar();*/
virtual void trigger();
virtual void keyPressEvent(QKeyEvent* e);
virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void updateMouseCursor();
void setMessage(QString msg);
bool isCompleted(){return completed;}
Plugin_Entity *getSelected(Doc_plugin_interface* d);
private:
bool completed;
QString message;
RS_Entity* en;
};
#endif

View File

@@ -0,0 +1,152 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include "qc_actiongetpoint.h"
#include <QPointF>
#include <QMouseEvent>
#include "rs_snapper.h"
#include "rs_dialogfactory.h"
#include "rs_graphicview.h"
#include "rs_line.h"
#include "rs_coordinateevent.h"
#include "rs_preview.h"
#include "rs_debug.h"
struct QC_ActionGetPoint::Points {
RS_MoveData data;
RS_Vector referencePoint;
RS_Vector targetPoint;
QString message;
};
QC_ActionGetPoint::QC_ActionGetPoint(RS_EntityContainer& container,
RS_GraphicView& graphicView)
:RS_PreviewActionInterface("Get Point",
container, graphicView)
, canceled(false)
, completed{false}
, setTargetPoint{false}
, pPoints(new Points{})
{
pPoints->targetPoint = RS_Vector(0,0);
}
QC_ActionGetPoint::~QC_ActionGetPoint() = default;
void QC_ActionGetPoint::trigger() {
RS_DEBUG->print("QC_ActionGetPoint::trigger()");
completed = true;
updateMouseButtonHints();
}
void QC_ActionGetPoint::mouseMoveEvent(QMouseEvent* e) {
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent begin");
RS_Vector mouse = snapPoint(e);
if(setTargetPoint){
if (pPoints->referencePoint.valid) {
pPoints->targetPoint = mouse;
deletePreview();
RS_Line *line =new RS_Line{preview.get(),
pPoints->referencePoint, mouse};
line->setPen(RS_Pen(RS_Color(0,0,0), RS2::Width00, RS2::DotLine ));
preview->addEntity(line);
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent: draw preview");
drawPreview();
preview->addSelectionFrom(*container);
}
} else {
pPoints->targetPoint = mouse;
}
RS_DEBUG->print("QC_ActionGetPoint::mouseMoveEvent end");
}
void QC_ActionGetPoint::mouseReleaseEvent(QMouseEvent* e) {
if (e->button()==Qt::LeftButton) {
RS_CoordinateEvent ce(snapPoint(e));
coordinateEvent(&ce);
} else if (e->button()==Qt::RightButton) {
canceled = true;
completed = true;
finish();
}
}
void QC_ActionGetPoint::coordinateEvent(RS_CoordinateEvent* e) {
if (e==nullptr) return;
RS_Vector pos = e->getCoordinate();
pPoints->targetPoint = pos;
graphicView->moveRelativeZero(pPoints->targetPoint);
trigger();
}
void QC_ActionGetPoint::updateMouseButtonHints() {
if (!completed)
RS_DIALOGFACTORY->updateMouseWidget(pPoints->message, tr("Cancel"));
else
RS_DIALOGFACTORY->updateMouseWidget();
}
void QC_ActionGetPoint::updateMouseCursor() {
graphicView->setMouseCursor(RS2::CadCursor);
}
void QC_ActionGetPoint::setBasepoint(QPointF* basepoint){
pPoints->referencePoint.x = basepoint->x();
pPoints->referencePoint.y = basepoint->y();
setTargetPoint = true;
}
void QC_ActionGetPoint::setMessage(QString msg){
pPoints->message = msg;
}
void QC_ActionGetPoint::getPoint(QPointF *point)
{
if (pPoints)
{
point->setX(pPoints->targetPoint.x);
point->setY(pPoints->targetPoint.y);
}
}
// EOF

View File

@@ -0,0 +1,72 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef QC_ACTIONGETPOINT_H
#define QC_ACTIONGETPOINT_H
#include "rs_previewactioninterface.h"
#include "rs_modification.h"
class QPointF;
/**
* This action class can handle user events to get a point from plugin.
*
* @author Rallaz
*/
class QC_ActionGetPoint : public RS_PreviewActionInterface {
Q_OBJECT
public:
QC_ActionGetPoint(RS_EntityContainer& container,
RS_GraphicView& graphicView);
~QC_ActionGetPoint();
virtual void trigger() override;
virtual void mouseMoveEvent(QMouseEvent* e) override;
virtual void mouseReleaseEvent(QMouseEvent* e) override;
virtual void coordinateEvent(RS_CoordinateEvent* e ) override;
virtual void updateMouseButtonHints() override;
virtual void updateMouseCursor() override;
void getPoint(QPointF *point);
void setBasepoint(QPointF* basepoint);
void setMessage(QString msg);
bool isCompleted(){return completed;}
bool wasCanceled(){return canceled;}
private:
bool canceled;
bool completed;
bool setTargetPoint;
struct Points;
std::unique_ptr<Points> pPoints;
};
#endif

View File

@@ -0,0 +1,112 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include <QMouseEvent>
#include <QKeyEvent>
#include "qc_actiongetselect.h"
#include "doc_plugin_interface.h"
#include "rs_dialogfactory.h"
#include "rs_graphicview.h"
#include "rs_actionselectsingle.h"
// #include <QDebug>
#include "rs_snapper.h"
QC_ActionGetSelect::QC_ActionGetSelect(RS_EntityContainer& container,
RS_GraphicView& graphicView)
:RS_ActionInterface("Get Select", container, graphicView)
,completed(false)
,message(tr("Select objects:"))
{
actionType = RS2::ActionGetSelect;
}
QC_ActionGetSelect::~QC_ActionGetSelect()
{
// qDebug() << "~QC_ActionGetSelect";
}
void QC_ActionGetSelect::updateMouseButtonHints() {
switch (getStatus()) {
case Select:
RS_DIALOGFACTORY->updateMouseWidget(message, tr("Cancel"));
break;
default:
RS_DIALOGFACTORY->updateMouseWidget();
break;
}
}
void QC_ActionGetSelect::updateMouseCursor() {
graphicView->setMouseCursor(RS2::SelectCursor);
}
void QC_ActionGetSelect::setMessage(QString msg){
message = msg;
}
void QC_ActionGetSelect::init(int status) {
RS_ActionInterface::init(status);
graphicView->setCurrentAction(
new RS_ActionSelectSingle(*container, *graphicView, this));
}
void QC_ActionGetSelect::mouseReleaseEvent(QMouseEvent* e) {
if (e->button()==Qt::RightButton) {
completed = true;
RS_DIALOGFACTORY->updateMouseWidget();
finish();
}
}
void QC_ActionGetSelect::keyPressEvent(QKeyEvent* e)
{
if (e->key()==Qt::Key_Escape || e->key()==Qt::Key_Enter)
{
RS_DIALOGFACTORY->updateMouseWidget();
finish();
completed = true;
}
}
/**
* Adds all selected entities from 'container' to the selection.
*/
void QC_ActionGetSelect::getSelected(QList<Plug_Entity *> *se, Doc_plugin_interface* d) const
{
for(auto e: *container){
if (e->isSelected()) {
Plugin_Entity *pe = new Plugin_Entity(e, d);
se->append(reinterpret_cast<Plug_Entity*>(pe));
}
}
}
// EOF

View File

@@ -0,0 +1,75 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef QC_ACTIONGETSELECT_H
#define QC_ACTIONGETSELECT_H
#include "rs_previewactioninterface.h"
#include "rs_modification.h"
class Plug_Entity;
class Doc_plugin_interface;
/**
* This action class can handle user events to select entities from plugin.
*
* @author Rallaz
*/
class QC_ActionGetSelect : public RS_ActionInterface {
Q_OBJECT
public:
/**
* Action States.
*/
enum Status {
Select
};
public:
QC_ActionGetSelect(RS_EntityContainer& container,
RS_GraphicView& graphicView);
~QC_ActionGetSelect();
virtual void init(int status=0);
virtual void mouseReleaseEvent(QMouseEvent* e);
virtual void keyPressEvent(QKeyEvent* e);
virtual void updateMouseButtonHints();
virtual void updateMouseCursor();
void setMessage(QString msg);
bool isCompleted() const{return completed;}
void getSelected(QList<Plug_Entity *> *se, Doc_plugin_interface* d) const;
private:
bool completed;
QString message;
};
#endif