mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-02 16:49:02 +00:00
Export to 3mf
This commit is contained in:
@@ -5,7 +5,6 @@ import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
@@ -21,7 +20,6 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -58,6 +56,7 @@ import ru.ytkab0bp.slicebeam.events.NeedDismissSnackbarEvent;
|
||||
import ru.ytkab0bp.slicebeam.events.NeedSnackbarEvent;
|
||||
import ru.ytkab0bp.slicebeam.events.ObjectsListChangedEvent;
|
||||
import ru.ytkab0bp.slicebeam.fragment.BedFragment;
|
||||
import ru.ytkab0bp.slicebeam.navigation.Fragment;
|
||||
import ru.ytkab0bp.slicebeam.navigation.MobileNavigationDelegate;
|
||||
import ru.ytkab0bp.slicebeam.navigation.NavigationDelegate;
|
||||
import ru.ytkab0bp.slicebeam.slic3r.Model;
|
||||
@@ -71,7 +70,8 @@ import ru.ytkab0bp.slicebeam.view.SnackbarsLayout;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
public final static int REQUEST_CODE_OPEN_FILE = 1, REQUEST_CODE_EXPORT_GCODE = 2,
|
||||
REQUEST_CODE_IMPORT_PROFILES = 3, REQUEST_CODE_EXPORT_PROFILES = 4;
|
||||
REQUEST_CODE_IMPORT_PROFILES = 3, REQUEST_CODE_EXPORT_PROFILES = 4,
|
||||
REQUEST_CODE_EXPORT_3MF = 5,
|
||||
|
||||
private static MainActivity activeInstance;
|
||||
|
||||
@@ -203,12 +203,39 @@ public class MainActivity extends AppCompatActivity {
|
||||
setIntent(null);
|
||||
}
|
||||
|
||||
/** @noinspection ResultOfMethodCallIgnored*/
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (requestCode == MainActivity.REQUEST_CODE_EXPORT_GCODE) {
|
||||
if (requestCode == MainActivity.REQUEST_CODE_EXPORT_3MF) {
|
||||
Fragment fragment = getNavigationDelegate().getCurrentFragment();
|
||||
if (fragment instanceof BedFragment) {
|
||||
try {
|
||||
OutputStream out = getContentResolver().openOutputStream(data.getData());
|
||||
Model model = ((BedFragment) fragment).getGlView().getRenderer().getModel();
|
||||
File tempFile = File.createTempFile("temp_project", ".3mf");
|
||||
SliceBeam.genCurrentConfig();
|
||||
File cfg = SliceBeam.getCurrentConfigFile();
|
||||
model.export3mf(cfg.getAbsolutePath(), tempFile.getAbsolutePath());
|
||||
|
||||
InputStream in = new FileInputStream(tempFile);
|
||||
byte[] buffer = new byte[10240];
|
||||
int c;
|
||||
while ((c = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, c);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
tempFile.delete();
|
||||
|
||||
SliceBeam.EVENT_BUS.fireEvent(new NeedSnackbarEvent(R.string.MenuFileExport3mfSuccess));
|
||||
} catch (IOException | Slic3rRuntimeError e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} else if (requestCode == MainActivity.REQUEST_CODE_EXPORT_GCODE) {
|
||||
try {
|
||||
OutputStream out = getContentResolver().openOutputStream(data.getData());
|
||||
InputStream in = new FileInputStream(BedFragment.getTempGCodePath());
|
||||
|
||||
@@ -167,6 +167,10 @@ public class Model {
|
||||
return new GCodeProcessorResult(Native.model_slice(pointer, configPath, gcodePath, listener));
|
||||
}
|
||||
|
||||
public void export3mf(String configPath, String _3mfPath) throws Slic3rRuntimeError {
|
||||
Native.model_export_3mf(pointer, configPath, _3mfPath);
|
||||
}
|
||||
|
||||
public void release() {
|
||||
if (pointer != 0) {
|
||||
Native.model_release(pointer);
|
||||
|
||||
@@ -76,6 +76,7 @@ class Native {
|
||||
static native int model_get_extruder(long ptr, int i);
|
||||
static native void model_set_extruder(long ptr, int i, int extruder);
|
||||
static native long model_slice(long ptr, String configPath, String path, SliceListener listener) throws Slic3rRuntimeError;
|
||||
static native void model_export_3mf(long ptr, String configPath, String path) throws Slic3rRuntimeError;
|
||||
static native void model_release(long ptr);
|
||||
|
||||
static native long gcoderesult_load_file(String path, String name);
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/ModelArrange.hpp"
|
||||
#include "libslic3r/SVG.hpp"
|
||||
#include "libslic3r/Geometry.hpp"
|
||||
#include "libslic3r/Arrange.hpp"
|
||||
#include "libslic3r/AABBMesh.hpp"
|
||||
#include "libslic3r/Geometry/ConvexHull.hpp"
|
||||
#include "libslic3r/Format/3mf.hpp"
|
||||
#include "bbl/Orient.hpp"
|
||||
#include "Viewer.hpp"
|
||||
|
||||
@@ -840,11 +840,10 @@ extern "C" {
|
||||
ModelRef* model = (ModelRef*) (intptr_t) ptr;
|
||||
|
||||
Print print;
|
||||
PresetBundle bundle;
|
||||
DynamicPrintConfig config;
|
||||
const char *chars = env->GetStringUTFChars(configPath, JNI_FALSE);
|
||||
config.load(std::string(chars), ForwardCompatibilitySubstitutionRule::Disable);
|
||||
env->ReleaseStringUTFChars(path, chars);
|
||||
env->ReleaseStringUTFChars(configPath, chars);
|
||||
config.normalize_fdm();
|
||||
|
||||
for (auto* mo : model->model.objects) {
|
||||
@@ -901,6 +900,24 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_ru_ytkab0bp_slicebeam_slic3r_Native_model_1export_13mf(JNIEnv* env, jclass, jlong ptr, jstring configPath, jstring path) {
|
||||
auto model = reinterpret_cast<ModelRef*>(ptr);
|
||||
|
||||
try {
|
||||
DynamicPrintConfig config;
|
||||
const char *chars = env->GetStringUTFChars(configPath, JNI_FALSE);
|
||||
config.load(std::string(chars), ForwardCompatibilitySubstitutionRule::Disable);
|
||||
env->ReleaseStringUTFChars(configPath, chars);
|
||||
config.normalize_fdm();
|
||||
|
||||
const char *pathChars = env->GetStringUTFChars(path, JNI_FALSE);
|
||||
Slic3r::store_3mf(pathChars, &model->model, &config, false, nullptr, false);
|
||||
env->ReleaseStringUTFChars(path, pathChars);
|
||||
} catch (const std::exception& e) {
|
||||
env->ThrowNew(env->FindClass("ru/ytkab0bp/slicebeam/slic3r/Slic3rRuntimeError"), e.what());
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_ru_ytkab0bp_slicebeam_slic3r_Native_model_1release(JNIEnv* env, jclass, jlong ptr) {
|
||||
ModelRef* model = (ModelRef*) (intptr_t) ptr;
|
||||
delete model;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="28dp"
|
||||
android:height="28dp"
|
||||
android:viewportWidth="28"
|
||||
android:viewportHeight="28">
|
||||
<path
|
||||
android:pathData="M15,3a1,1 0,1 0,-2 0v13.586l-2.293,-2.293a1,1 0,0 0,-1.414 1.414l4,4 0.006,0.007a1,1 0,0 0,0.698 0.286h0.006a0.996,0.996 0,0 0,0.697 -0.286l0.008,-0.008 4,-3.999a1,1 0,0 0,-1.415 -1.414L15,16.586V3ZM8.98,6h-0.02c-1.525,0.062 -2.332,0.299 -3.145,0.733a5.02,5.02 0,0 0,-2.082 2.082C3.194,9.823 3,10.814 3,13.023v5.954c0,2.21 0.194,3.2 0.733,4.208a5.02,5.02 0,0 0,2.082 2.082c1.008,0.539 1.999,0.733 4.208,0.733h7.954c2.21,0 3.2,-0.194 4.208,-0.733a5.019,5.019 0,0 0,2.082 -2.082c0.539,-1.008 0.733,-1.999 0.733,-4.207v-5.956c0,-2.208 -0.194,-3.2 -0.733,-4.207a5.02,5.02 0,0 0,-2.082 -2.082c-0.813,-0.434 -1.62,-0.67 -3.145,-0.732L19.02,6H18a1,1 0,1 0,0 2h0.98c1.28,0.053 1.776,0.237 2.261,0.497 0.547,0.292 0.97,0.715 1.262,1.262 0.307,0.572 0.497,1.168 0.497,3.264v5.954c0,2.096 -0.19,2.692 -0.497,3.264a3.02,3.02 0,0 1,-1.262 1.262c-0.572,0.307 -1.168,0.497 -3.264,0.497h-7.954c-2.096,0 -2.692,-0.19 -3.264,-0.497a3.02,3.02 0,0 1,-1.262 -1.262C5.19,21.67 5,21.073 5,18.977v-5.954c0,-2.096 0.19,-2.691 0.497,-3.264a3.02,3.02 0,0 1,1.262 -1.262c0.485,-0.26 0.98,-0.444 2.262,-0.497H10a1,1 0,1 0,0 -2H8.98Z"
|
||||
android:fillColor="#000"/>
|
||||
</vector>
|
||||
@@ -42,6 +42,8 @@
|
||||
<string name="MenuFileExportProfilesPrinters">Принтеры</string>
|
||||
<string name="MenuFileExportProfilesNoProfiles">Не выбрано ни одного профиля.</string>
|
||||
<string name="MenuFileExportProfilesSuccess">Профили успешно экспортированы.</string>
|
||||
<string name="MenuFileExport3mf">Экспорт. 3mf</string>
|
||||
<string name="MenuFileExport3mfSuccess">Успешно экспортировали проект.</string>
|
||||
<string name="MenuCamera">Камера</string>
|
||||
<string name="MenuCameraIsometric">Изомет.\nвид</string>
|
||||
<string name="MenuCameraTop">Вид\nсверху</string>
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
<string name="MenuFileExportProfilesPrinters">Printers</string>
|
||||
<string name="MenuFileExportProfilesNoProfiles">No profiles selected.</string>
|
||||
<string name="MenuFileExportProfilesSuccess">Exported profiles successfully.</string>
|
||||
<string name="MenuFileExport3mf">Export 3mf</string>
|
||||
<string name="MenuFileExport3mfSuccess">Successfully exported project.</string>
|
||||
<string name="MenuCamera">Camera</string>
|
||||
<string name="MenuCameraIsometric">Isom. view</string>
|
||||
<string name="MenuCameraTop">Top view</string>
|
||||
|
||||
Reference in New Issue
Block a user