void Update() { switch (StageManager.GetCurStage()) { case StageManager.Stage_Enum.Idle: Application.runInBackground = false; break; case StageManager.Stage_Enum.Load_Model: Application.runInBackground = ModelManager.GetInstance().GetInfo().isParsing; break; case StageManager.Stage_Enum.Gcode_Create: Application.runInBackground = GcodeCreateManager.GetInstance().GetInfo().isSlicing; break; case StageManager.Stage_Enum.Gcode_Render: Application.runInBackground = GcodeRenderManager.GetInstance().GetInfo().isParsing; break; case StageManager.Stage_Enum.Gcode_Send: Application.runInBackground = GcodeSenderManager.GetInstance().GetInfo().sending_GcodeFile; break; } }
public void Reset() { //1.check if (!CanExecuteReset()) { Debug.Log("Can not execute reset" + "\n"); return; } //2.handle gcode render GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean(); GcodeRenderManager.GetInstance().Destroy(); //3.remove all bean except initBean while (_undoStack.Count > 1) { _undoStack.Pop(); } _redoStack.Clear(); OperateBean initRenderBean = _undoStack.Peek(); Debug.Log("Reset:" + "\n" + _curOperateBean + "-->" + "\n" + initRenderBean + "\n"); operateRenderModel(initRenderBean); _curOperateBean = initRenderBean.DeepCopy(); }
private void onClick_export() { if (StageManager.GetStageList().Contains(StageManager.Stage_Enum.Gcode_Render) && GcodeRenderManager.GetInstance().GetInfo().isRendered&& StageManager.GetCurStage() != StageManager.Stage_Enum.Gcode_Send) { if (GcodeRenderManager.GetInstance().IsInBounds()) { string path = ModelManager.GetInstance().GetInfo().modelPath; string defaultName = System.IO.Path.GetFileNameWithoutExtension(path); string exportPath = FileDialogManager.GetInstance().ShowFileSaveDialog_Gcode(defaultName); if (string.IsNullOrEmpty(exportPath) || exportPath.Trim().Length == 0) { Debug.LogWarning("Gcode export is empty"); } else { string originPath = GcodeCreateManager.GetInstance().curGcodeBean.gcodePath; startSubThreadToExportGcode(originPath, exportPath); } } else { AlertMananger.GetInstance().ShowAlertMsg("Unable to print. The model goes beyond the work area."); } } }
/*************** preview ***************/ void onClick_preview() { if (ModelManager.GetInstance().GetModel() == null) { AlertMananger.GetInstance().ShowToast("Please open a file to preview."); return; } if (!ModelManager.GetInstance().GetInfo().printable) { AlertMananger.GetInstance().ShowToast("Please move, scale or rotate the model so that it's within the build volume."); return; } if (!ConfigManager.GetInstance().GetSelectedMyBean().IsValuesAvailable()) { AlertMananger.GetInstance().ShowToast("Invalid configuration. Please check."); GameObject.Find("panel_configDisplay").GetComponent <ControlConfigDisplay>().ShowConfigDisplayPanelAnima(); return; } Vector3 size = ModelManager.GetInstance().GetModel().GetCurDataSize(); if (size.x < 2 && size.y < 2 && size.z < 2) { AlertMananger.GetInstance().ShowToast("Model is too tiny to print."); return; } //model is too thin to print //todo change content of alert msg if (ModelManager.GetInstance().GetRenderOperateBean().size.z < ConfigManager.GetInstance().GetSelectedMyBean().bean.overrides.layer_height.default_value) { AlertMananger.GetInstance().ShowAlertMsg("The thickness of model is less than 1 layer. Modify model or decrease the value of ‘Layer Height’."); return; } string stlFilepath = ModelManager.GetInstance().SaveModelAsStlFile(); string configJsonFilePath = Application.streamingAssetsPath + "/CrossPlatform/CuraEngine/Config/" + "output.def.json"; ConfigManager.GetInstance().GetSelectedMyBean().ArchiveForPrint(configJsonFilePath); if (StageManager.GetStageList().Contains(StageManager.Stage_Enum.Gcode_Render)) { if (!GcodeCreateManager.GetInstance().NeedSlice(stlFilepath, configJsonFilePath)) { AlertMananger.GetInstance().ShowToast("You are already in Preview."); return; } } GcodeRenderManager.GetInstance().Destroy(); GcodeCreateManager.GetInstance().StartSubThread_CreateGcode(stlFilepath, configJsonFilePath); }
public static GcodeCreateManager GetInstance() { if (_INSTANCE == null) { _INSTANCE = new GcodeCreateManager(); _INSTANCE.curGcodeBean = new GcodeCreateBean(); _INSTANCE._infoStruct.isSlicing = false; _INSTANCE._infoStruct.progress = 0.0f; _INSTANCE._infoStruct.isCurGcodeCreateBeanAvailable = false; } return(_INSTANCE); }
public void Redo() { //1.check if (!CanExecuteRedo()) { Debug.Log("Can not execute redo" + "\n"); return; } //handle gcode render GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean(); GcodeRenderManager.GetInstance().Destroy(); //_undoStack Pop and _redoStack push _undoStack.Push(_redoStack.Pop()); OperateBean targetRenderBean = _undoStack.Peek(); Debug.Log("redo:" + "\n" + _curOperateBean + "-->" + "\n" + targetRenderBean + "\n"); operateRenderModel(targetRenderBean); _curOperateBean = targetRenderBean.DeepCopy(); }
void onClick_print() { string gcodePath = GcodeCreateManager.GetInstance().curGcodeBean.gcodePath; GcodeSenderManager.GetInstance().StartSend(gcodePath); }
public void OnOperateEnd() { //1.check if (_model3d == null) { return; } OperateBean lastBean = _undoStack.Peek(); if (lastBean.scale == _curOperateBean.scale && lastBean.move == _curOperateBean.move && lastBean.rotate == _curOperateBean.rotate) { Debug.Log("Model is not moved/scaled/rotated, return" + "\n"); GcodeRenderManager.GetInstance().SetActive_gcodeRender(true); return; } UnityEngine.Debug.Log("************************ OnOperateEnd ***************************" + "\n"); //2.release about gcode GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean(); GcodeRenderManager.GetInstance().Destroy(); //3.operate bool moveChanged = lastBean.move != _curOperateBean.move; bool scaleChanged = lastBean.scale != _curOperateBean.scale; bool rotateChanged = lastBean.rotate != _curOperateBean.rotate; if (moveChanged) { Debug.Log("Model is moved" + "\n"); } if (scaleChanged) { Debug.Log("Model is scaled" + "\n"); } if (rotateChanged) { Debug.Log("Model is rotated" + "\n"); } //case1: only move param changed if (moveChanged && !scaleChanged && !rotateChanged) { //No need to update dataModel, vertical value not changed //update dataModel may costs lot time Debug.Log("Model is only moved" + "\n"); } else { //case2: scale/rotate changed Debug.Log("Model is scaled/rotated" + "\n"); //UpdateCurDataModel //dataModel will change _model3d.UpdateCurDataModel( _curOperateBean.scale, _curOperateBean.move.x, _curOperateBean.move.y, _curOperateBean.rotate.x, _curOperateBean.rotate.y, _curOperateBean.rotate.z ); //set render position float minZ_cur = _model3d.dataModel_cur.GetMinZ(); float minZ_origin = _model3d.dataModel_origin.GetMinZ(); float disZ = minZ_origin - minZ_cur; Vector3 newPosition = _model3d.renderedModel.shellCube.transform.localPosition; float y = -(_deviceSize.y - _model3d.GetOriginDataSize().z) / 2.0f; float localY = y / _deviceSize.y; newPosition.y = localY + disZ / _deviceSize.y; _model3d.renderedModel.shellCube.transform.localPosition = newPosition; //record _curOperateBean.localPosition = newPosition; //after UpdateCurDataModel and operate render model, //the dataModel_cur.GetSize is actural renderModel size _curOperateBean.size = _model3d.dataModel_cur.GetSize(); } //4.undo/redo _undoStack.Push(_curOperateBean.DeepCopy()); _redoStack.Clear(); UnityEngine.Debug.Log("***************************************************" + "\n"); }
void Update() { btn_pause.GetComponent <Transform> ().gameObject.SetActive(false); switch (StageManager.GetCurStage()) { case StageManager.Stage_Enum.Idle: case StageManager.Stage_Enum.Load_Model: panel_content.SetActive(false); break; case StageManager.Stage_Enum.Gcode_Create: panel_content.SetActive(true); //widget : invisible btn_stop.GetComponent <Transform> ().gameObject.SetActive(false); text_nozzle.GetComponent <Transform> ().gameObject.SetActive(false); text_bed.GetComponent <Transform> ().gameObject.SetActive(false); text_nozzle_temp.GetComponent <Transform> ().gameObject.SetActive(false); text_bed_temp.GetComponent <Transform> ().gameObject.SetActive(false); // btn_pause.interactable = false; // btn_stop.interactable = false; // btn_pause.GetComponentInChildren<Text> ().text = "Pause"; // img_pause_icon.sprite = Resources.Load ("Images/Pause-Icon", typeof(Sprite))as Sprite; //progress float sliceProgress = GcodeCreateManager.GetInstance().GetInfo().progress; text_print_progress.text = "Slicing : " + (((int)(sliceProgress * 1000)) / 10.0f).ToString("0.0") + "%"; image_print_progress.fillAmount = sliceProgress; break; case StageManager.Stage_Enum.Gcode_Render: //widget : invisible btn_stop.GetComponent <Transform> ().gameObject.SetActive(false); text_nozzle.GetComponent <Transform> ().gameObject.SetActive(false); text_bed.GetComponent <Transform> ().gameObject.SetActive(false); text_nozzle_temp.GetComponent <Transform> ().gameObject.SetActive(false); text_bed_temp.GetComponent <Transform> ().gameObject.SetActive(false); if (GcodeRenderManager.GetInstance().GetInfo().isParsing) { panel_content.SetActive(true); //show render progress float progress = GcodeRenderManager.GetInstance().GetInfo().parseProgress; text_print_progress.text = "Rendering : " + (((int)(progress * 1000)) / 10.0f).ToString("0.0") + "%"; image_print_progress.fillAmount = progress; } else { panel_content.SetActive(false); } break; case StageManager.Stage_Enum.Gcode_Send: { panel_content.SetActive(true); //widget : invisible btn_stop.GetComponent <Transform> ().gameObject.SetActive(true); text_nozzle.GetComponent <Transform> ().gameObject.SetActive(true); text_bed.GetComponent <Transform> ().gameObject.SetActive(true); text_nozzle_temp.GetComponent <Transform> ().gameObject.SetActive(true); text_bed_temp.GetComponent <Transform> ().gameObject.SetActive(true); //temp float temp_cur_bed = GcodeSenderManager.GetInstance().GetInfo().temp_cur_bed; float temp_tar_bed = GcodeSenderManager.GetInstance().GetInfo().temp_target_bed; float temp_cur_nozzle = GcodeSenderManager.GetInstance().GetInfo().temp_cur_nozzle; float temp_tar_nozzle = GcodeSenderManager.GetInstance().GetInfo().temp_target_nozzle; text_bed_temp.text = Math.Round(temp_cur_bed) + "/" + temp_tar_bed + "°C"; text_nozzle_temp.text = Math.Round(temp_cur_nozzle) + "/" + temp_tar_nozzle + "°C"; //progress float progress = GcodeSenderManager.GetInstance().GetInfo().progress; text_print_progress.text = "Waiting : " + (((int)(progress * 1000)) / 10.0f).ToString("0.0") + "%"; image_print_progress.fillAmount = progress; if (GcodeSenderManager.GetInstance().GetInfo().sending_GcodeFile) { btn_pause.interactable = true; btn_stop.interactable = true; btn_pause.GetComponentInChildren <Text> ().text = "PAUSE"; img_pause_icon.sprite = Resources.Load("Images/Pause-Icon", typeof(Sprite)) as Sprite; } else { btn_pause.interactable = true; btn_stop.interactable = true; btn_pause.GetComponentInChildren <Text> ().text = "START"; img_pause_icon.sprite = Resources.Load("Images/START-Icon", typeof(Sprite)) as Sprite; } } break; } }
/*************** life cycle ***************/ void Awake() { GcodeCreateManager.GetInstance().AddListener(this); }
void Update() { //1.set active bool active = StageManager.GetCurStage() != StageManager.Stage_Enum.Idle; panel_content.SetActive(active); if (!active) { return; } //2.set model file name string modelFileName = System.IO.Path.GetFileName(ModelManager.GetInstance().GetInfo().modelPath); //file name is too long, so cut if (!string.IsNullOrEmpty(modelFileName) && modelFileName.Length > 32) { modelFileName = modelFileName.Substring(0, 14) + "..." + modelFileName.Substring(modelFileName.Length - 14, 14); } else { modelFileName = ""; } text_modeFileName.text = modelFileName; //3.set text_printTime and text_materialCost if (!GcodeCreateManager.GetInstance().GetInfo().isCurGcodeCreateBeanAvailable) { text_printTime.text = "~ h ~ min"; text_materialCost.text = "~ m / ~ g"; } else { if (GcodeCreateManager.GetInstance().curGcodeBean.printTime <= 0) { text_printTime.text = "~ h ~ min"; text_materialCost.text = "~ m / ~ g"; } else { int hours = GcodeCreateManager.GetInstance().curGcodeBean.printTime / 3600; int minutes = (GcodeCreateManager.GetInstance().curGcodeBean.printTime - hours * 3600) / 60; //less than 1 minute if (hours == 0 && minutes < 1) { minutes = 1; } string printTimeStr = hours > 0 ? (hours + " h " + minutes + " min") : (minutes + " min"); text_printTime.text = printTimeStr; float materialLength = GcodeCreateManager.GetInstance().curGcodeBean.filamentLength; if (materialLength < 0.1f) { materialLength = 0.1f; } int materialWeight = Mathf.CeilToInt(GcodeCreateManager.GetInstance().curGcodeBean.filamentWeight); string materialCostStr = materialLength.ToString("0.0") + "m / " + materialWeight + "g"; text_materialCost.text = materialCostStr; } } //4.set size Vector3 size = Vector3.zero; if (ModelManager.GetInstance().GetModel() != null) { size = ModelManager.GetInstance().GetRenderOperateBean().size; } text_modelSize.text = size.x.ToString("0.0") + " x " + size.y.ToString("0.0") + " x " + size.z.ToString("0.0") + " mm"; //5.set image icon position { //move material icon next to text_materialCost Vector3 newPos_imgMaterial = image_material.transform.localPosition; newPos_imgMaterial.x = -Utils.CalculateTextLength(text_materialCost) + 100; image_material.transform.localPosition = newPos_imgMaterial; } { //move time icon next to text_printTime Vector3 newPos_imgTime = image_time.transform.localPosition; newPos_imgTime.x = -Utils.CalculateTextLength(text_printTime) + 100; image_time.transform.localPosition = newPos_imgTime; } }