Mesh: [skip ci] allow to set custom size for asymptote output

This commit is contained in:
wmayer
2020-08-29 19:05:28 +02:00
parent 4c233cd9e9
commit 9dfd40e4d3
5 changed files with 86 additions and 1 deletions

View File

@@ -28,6 +28,7 @@
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <App/Application.h>
#include "Mesh.h"
#include "MeshPy.h"
@@ -57,6 +58,11 @@ PyMOD_INIT_FUNC(Mesh)
// NOTE: To finish the initialization of our own type objects we must
// call PyType_Ready, otherwise we run into a segmentation fault, later on.
// This function is responsible for adding inherited slots from a type's base class.
ParameterGrp::handle handle = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Mod/Mesh");
ParameterGrp::handle asy = handle->GetGroup("Asymptote");
MeshCore::MeshOutput::SetAsymptoteSize(asy->GetASCII("Width", "500"),
asy->GetASCII("Height"));
// add mesh elements
Base::Interpreter().addType(&Mesh::MeshPointPy ::Type,meshModule,"MeshPoint");

View File

@@ -1755,6 +1755,15 @@ void MeshOutput::SetSTLHeaderData(const std::string& header)
}
}
std::string MeshOutput::asyWidth = "500";
std::string MeshOutput::asyHeight = "500";
void MeshOutput::SetAsymptoteSize(const std::string& w, const std::string& h)
{
asyWidth = w;
asyHeight = h;
}
void MeshOutput::Transform(const Base::Matrix4D& mat)
{
_transform = mat;
@@ -2404,7 +2413,12 @@ bool MeshOutput::SaveAsymptote(std::ostream &out) const
out << "import three;\n\n";
out << "size(500);\n\n";
if (!asyWidth.empty()) {
out << "size(" << asyWidth;
if (!asyHeight.empty())
out << ", " << asyHeight;
out << ");\n\n";
}
Base::BoundBox3f bbox = _rclMesh.GetBoundBox();
Base::Vector3f center = bbox.GetCenter();

View File

@@ -166,6 +166,10 @@ public:
* automatically filled up with spaces.
*/
static void SetSTLHeaderData(const std::string&);
/**
* Change the image size of the asymptote output.
*/
static void SetAsymptoteSize(const std::string&, const std::string&);
/// Determine the mesh format by file extension
static MeshIO::Format GetFormat(const char* FileName);
/// Saves the file, decided by extension if not explicitly given
@@ -228,6 +232,7 @@ protected:
std::string objectName;
std::vector<Group> _groups;
static std::string stl_header;
static std::string asyWidth, asyHeight;
};
/*!

View File

@@ -82,6 +82,54 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="GroupBoxAsy">
<property name="title">
<string notr="true">Asymptote</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelAsyWidth">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="asymptoteWidth">
</widget>
</item>
<item row="0" column="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>61</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="3">
<widget class="QLabel" name="labelAsyHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLineEdit" name="asymptoteHeight">
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>

View File

@@ -25,6 +25,7 @@
#include "DlgSettingsImportExportImp.h"
#include "ui_DlgSettingsImportExport.h"
#include <App/Application.h>
#include <Mod/Mesh/App/Core/MeshIO.h>
using namespace MeshGui;
@@ -51,6 +52,13 @@ void DlgSettingsImportExport::saveSettings()
handle->SetFloat("MaxDeviationExport", value);
ui->exportAmfCompressed->onSave();
ParameterGrp::handle asy = handle->GetGroup("Asymptote");
asy->SetASCII("Width", ui->asymptoteWidth->text().toLatin1());
asy->SetASCII("Height", ui->asymptoteHeight->text().toLatin1());
MeshCore::MeshOutput::SetAsymptoteSize(ui->asymptoteWidth->text().toStdString(),
ui->asymptoteHeight->text().toStdString());
}
void DlgSettingsImportExport::loadSettings()
@@ -62,6 +70,10 @@ void DlgSettingsImportExport::loadSettings()
ui->maxDeviationExport->setValue(value);
ui->exportAmfCompressed->onRestore();
ParameterGrp::handle asy = handle->GetGroup("Asymptote");
ui->asymptoteWidth->setText(QString::fromStdString(asy->GetASCII("Width")));
ui->asymptoteHeight->setText(QString::fromStdString(asy->GetASCII("Height")));
}
/**