public static bool isOpenedWindow() { try { Process[] processList = Process.GetProcessesByName("femm"); if (processList.Length > 1) { CNotice.noticeWarningID("OOFP"); return(false); } if (processList.Length != 1) { return(false); } Process femmProcess = processList[0]; // Window 닫혀 있으면 Main Window Handle 값이 null 이다. if (femmProcess.MainWindowTitle != "") { return(true); } else { return(false); } } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } }
// 파일스트림 객체에 코일 정보를 기록한다. // override 를 꼭 사용해야 가상함수가 아니라 현 함수가 호출된다. public override bool writeObject(StreamWriter writeStream, int nLevel) { try { CWriteFile writeFile = new CWriteFile(); writeFile.writeBeginLine(writeStream, "ForceTest", nLevel); // CNode writeFile.writeDataLine(writeStream, "NodeName", NodeName, nLevel + 1); writeFile.writeDataLine(writeStream, "KindKey", KindKey, nLevel + 1); // CTest writeFile.writeDataLine(writeStream, "MeshSizePercent", MeshSizePercent, nLevel + 1); // CForceTest writeFile.writeDataLine(writeStream, "Voltage", Voltage, nLevel + 1); writeFile.writeDataLine(writeStream, "Current", Current, nLevel + 1); writeFile.writeDataLine(writeStream, "MovingStroke", MovingStroke, nLevel + 1); writeFile.writeEndLine(writeStream, "ForceTest", nLevel); } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } return(true); }
// 파일스트림 객체에 코일 정보를 기록한다. // override 를 꼭 사용해야 가상함수가 아니라 현 함수가 호출된다. public override bool writeObject(StreamWriter writeStream, int nLevel) { try { CWriteFile writeFile = new CWriteFile(); writeFile.writeBeginLine(writeStream, "Non-Kind", nLevel); // CNode writeFile.writeDataLine(writeStream, "NodeName", NodeName, nLevel + 1); writeFile.writeDataLine(writeStream, "KindKey", KindKey, nLevel + 1); // Non Kind 는 CNode 의 정보와 CShapParts 의 Face 정보만 필요하기 때문에 // 나머지 정보는 저장하지 않는다. // // CShapeParts //writeFile.writeDataLine(writeStream, "MovingParts", MovingPart, nLevel + 1); // CFace if (Face != null) { Face.writeObject(writeStream, nLevel + 1); } writeFile.writeEndLine(writeStream, "Non-Kind", nLevel); } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } return(true); }
// 파일스트림 객체에 코일 정보를 기록한다. // override 를 꼭 사용해야 가상함수가 아니라 현 함수가 호출된다. public override bool writeObject(StreamWriter writeStream, int nLevel) { try { CWriteFile writeFile = new CWriteFile(); writeFile.writeBeginLine(writeStream, "Magnet", nLevel); // CNode writeFile.writeDataLine(writeStream, "NodeName", NodeName, nLevel + 1); writeFile.writeDataLine(writeStream, "KindKey", KindKey, nLevel + 1); // CParts writeFile.writeDataLine(writeStream, "MovingParts", MovingPart, nLevel + 1); // CMagnet writeFile.writeDataLine(writeStream, "Material", m_strMaterialName, nLevel + 1); writeFile.writeDataLine(writeStream, "MagnetDirection", emMagnetDirection, nLevel + 1); // CFace if (Face != null) { Face.writeObject(writeStream, nLevel + 1); } writeFile.writeEndLine(writeStream, "Magnet", nLevel); } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } return(true); }
public void selectArc(CPoint selectPoint) { string strCommand; try { /// nodes, segments, arcsegments, blocks, group strCommand = "mi_seteditmode(\"arcsegments\")"; sendCommand(strCommand); strCommand = "mi_selectarcsegment(" + selectPoint.X + "," + selectPoint.Y + ")"; sendCommand(strCommand); /// editmode 를 group 으로 바꾸어서 FEMM 마우스 동작을 막는다. /// - refreshView() 전에 실행해야 한다. lockEdit(); /// refresh 를 꼭 해야 색상이 변한다 refreshView(); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public CScriptFEMM() { try { m_strBC = "\"" + "BC" + "\""; string strCommand; /// FEMM 이 실행되지 않은 상태에서 sendCommand 만 호출하면 FEMM 이 실행된다. /// 그런데 newdocument(0) 란 명령어로 FEMM 을 실행 시키면 실행과 동시에 Document 가 만들어질 때 문제가 발생한다. /// 이를 해결하기 위해서 아래와 같이 FEMM 프로세스를 먼저 호출하고 Document 를 연다 CProgramFEMM.loadProcessOfFEMM(); // 스크립트 생성과 동시에 전자기장 모델를 시작한다. strCommand = "newdocument(0)"; sendCommand(strCommand); strCommand = "mi_probdef(0,\"millimeters\",\"axi\")"; sendCommand(strCommand); //strCommand = "mi_setgrid(0.5,\"cart\")"; strCommand = "mi_hidegrid()"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public static void showFEMM() { try { Process[] processList = Process.GetProcessesByName("femm"); if (processList.Length > 1) { CNotice.noticeWarningID("OOFP"); return; } if (processList.Length != 1) { return; } Process femmProcess = processList[0]; Thread.Sleep(100); // 윈도우가 최소화 되어 있다면 활성화 시킨다 ShowWindowAsync(femmProcess.MainWindowHandle, SW_SHOWNORMAL); // 윈도우에 포커스를 줘서 최상위로 만든다 SetForegroundWindow(femmProcess.MainWindowHandle); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public static void moveFEMM(int iPosX, int iPosY, int iSizeX = 500, int iSizeY = 900) { try { Process[] processList = Process.GetProcessesByName("femm"); if (processList.Length > 1) { CNotice.noticeWarningID("OOFP"); return; } if (processList.Length != 1) { return; } Process femmProcess = processList[0]; Thread.Sleep(100); MoveWindow(femmProcess.MainWindowHandle, iPosX, iPosY, iSizeX, iSizeY, true); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public bool saveSettingToFile() { string strAppDataPath = Environment.GetEnvironmentVariable("APPDATA"); string strSettingFilePath = Path.Combine(strAppDataPath, "DoSA-2D"); string strSettingFileFullName = Path.Combine(strSettingFilePath, "setting.ini"); try { XmlSerializer xmlSerializer = new XmlSerializer(typeof(CSettingDataClone)); StreamWriter writer = new StreamWriter(strSettingFileFullName); // Static 객체는 XML Serialize 가 불가능해서 일반 Clone 객체에 복사를 하고 Serialize 를 하고 있다. CSettingDataClone settingData = new CSettingDataClone(); settingData.copySettingDataToClone(); xmlSerializer.Serialize(writer, settingData); writer.Close(); } catch (Exception ex) { CNotice.printLog(ex.Message); } return(true); }
public void saveAs(string strTestFullName) { string strCommand; try { //------------------------------------------------------------- // 아주 중요 //------------------------------------------------------------- // // 디렉토리에 들어있는 \\ 기호는 FEMM 에서 인식하지 못한다. // 따라서 디렉토리안의 \\ 기호를 / 기호로 변경한다 strTestFullName = strTestFullName.Replace("\\", "/"); //------------------------------------------------------------- strTestFullName = "\"" + strTestFullName + "\""; strCommand = "mi_saveas(" + strTestFullName + ")"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public static bool loadProcessOfFEMM() { try { if (checkFEMMInMemory() != true) { m_FEMM = new ActiveFEMMClass(); if (m_FEMM == null) { return(false); } else { return(true); } } return(true); } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } }
public void openDesign(string strTestFullName) { string strCommand; //------------------------------------------------------------- // 아주 중요 //------------------------------------------------------------- // // 디렉토리에 들어있는 \\ 기호는 FEMM 에서 인식하지 못한다. // 따라서 디렉토리안의 \\ 기호를 / 기호로 변경한다 strTestFullName = strTestFullName.Replace("\\", "/"); //------------------------------------------------------------- strTestFullName = "\"" + strTestFullName + "\""; try { /// nodes, segments, arcsegments, blocks, group strCommand = "open(" + strTestFullName + ")"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
/// <summary> /// 그룹 선택을 통해 모든 객체들을 삭제한다. /// </summary> public void deleteAll() { string strCommand; try { /// 기본 그룹을 삭제한다. strCommand = "mi_selectgroup(" + 0.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_deleteselected()"; sendCommand(strCommand); /// 이동 그룹을 삭제한다. strCommand = "mi_selectgroup(" + MOVING_GROUP_NUM.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_deleteselected()"; sendCommand(strCommand); refreshView(); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
private void buttonHomepage_Click(object sender, EventArgs e) { string target; if (CSettingData.m_emLanguage == EMLanguage.Korean) { target = "https://solenoid.or.kr/index_dosa_open_2d_kor.html"; } else { target = "https://solenoid.or.kr/index_dosa_open_2d_eng.html"; } try { System.Diagnostics.Process.Start(target); } catch (System.ComponentModel.Win32Exception noBrowser) { if (noBrowser.ErrorCode == -2147467259) { CNotice.printLog(noBrowser.Message); } } catch (System.Exception other) { CNotice.printLog(other.Message); } }
public void drawArc(double x1, double y1, double x2, double y2, bool bDirectionArcBackword, EMMoving emMoving = EMMoving.FIXED) { string strCommand; float fX1, fY1, fX2, fY2; fX1 = (float)x1; fY1 = (float)y1; fX2 = (float)x2; fY2 = (float)y2; try { strCommand = "mi_addnode(" + fX1.ToString() + "," + fY1.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_addnode(" + fX2.ToString() + "," + fY2.ToString() + ")"; sendCommand(strCommand); if (bDirectionArcBackword == true) { strCommand = "mi_addarc(" + fX2.ToString() + "," + fY2.ToString() + "," + fX1.ToString() + "," + fY1.ToString() + "," + "90, 1)"; sendCommand(strCommand); } else { strCommand = "mi_addarc(" + fX1.ToString() + "," + fY1.ToString() + "," + fX2.ToString() + "," + fY2.ToString() + "," + "90, 1)"; sendCommand(strCommand); } /// 그룹을 지정하는 경우만 변경을 한다. if (emMoving == EMMoving.MOVING) { /// 그룹 설정 /// - Point 의 선택이 좌표계산 없이 바로 가능함 /// - 또한 Point 만 그룹을 지정해도 이동이 가능하기 때문에 Point 만 설정함 strCommand = "mi_selectnode(" + fX1.ToString() + "," + fY1.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_selectnode(" + fX2.ToString() + "," + fY2.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_setgroup(" + MOVING_GROUP_NUM.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_clearselected()"; sendCommand(strCommand); } } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void setBlockProp(CPoint point, string strMaterial, double dMeshsize, string strCircuit, double dMagnetAngle, EMMoving emMoving, int nTurns) { string strCommand; try { /// mode 변경 없이도 동작은 한다. strCommand = "mi_seteditmode(\"blocks\")"; sendCommand(strCommand); strCommand = "mi_addblocklabel(" + point.X + "," + point.Y + ")"; sendCommand(strCommand); strCommand = "mi_selectlabel(" + point.X + "," + point.Y + ")"; sendCommand(strCommand); int nGroup; if (emMoving == EMMoving.MOVING) { nGroup = MOVING_GROUP_NUM; } else { nGroup = 0; } strMaterial = "\"" + strMaterial + "\""; strCircuit = "\"" + strCircuit + "\""; strCommand = "mi_setblockprop(" + strMaterial + ",0," + dMeshsize.ToString() + "," + strCircuit + "," + dMagnetAngle.ToString() + "," + nGroup.ToString() + "," + nTurns.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_clearselected()"; sendCommand(strCommand); // editmode 를 group 으로 바꾸어서 FEMM 마우스 동작을 막는다. lockEdit(); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
// 파일스트림 객체에 코일 정보를 기록한다. // override 를 꼭 사용해야 가상함수가 아니라 현 함수가 호출된다. public override bool writeObject(StreamWriter writeStream, int nLevel) { try { CWriteFile writeFile = new CWriteFile(); writeFile.writeBeginLine(writeStream, "Coil", nLevel); // CNode writeFile.writeDataLine(writeStream, "NodeName", NodeName, nLevel + 1); writeFile.writeDataLine(writeStream, "KindKey", KindKey, nLevel + 1); // CParts writeFile.writeDataLine(writeStream, "MovingParts", MovingPart, nLevel + 1); // CCoil writeFile.writeDataLine(writeStream, "Material", MaterialName, nLevel + 1); writeFile.writeDataLine(writeStream, "CurrentDirection", CurrentDirection, nLevel + 1); writeFile.writeDataLine(writeStream, "Turns", Turns, nLevel + 1); writeFile.writeDataLine(writeStream, "Resistance", Resistance, nLevel + 1); writeFile.writeDataLine(writeStream, "Resistance_20", Resistance_20, nLevel + 1); writeFile.writeDataLine(writeStream, "Layers", Layers, nLevel + 1); writeFile.writeDataLine(writeStream, "TurnsOfOneLayer", TurnsOfOneLayer, nLevel + 1); writeFile.writeDataLine(writeStream, "CoilWireGrade", CoilWireGrade, nLevel + 1); writeFile.writeDataLine(writeStream, "InnerDiameter", InnerDiameter, nLevel + 1); writeFile.writeDataLine(writeStream, "OuterDiameter", OuterDiameter, nLevel + 1); writeFile.writeDataLine(writeStream, "Height", Height, nLevel + 1); writeFile.writeDataLine(writeStream, "CopperDiameter", CopperDiameter, nLevel + 1); writeFile.writeDataLine(writeStream, "WireDiameter", WireDiameter, nLevel + 1); writeFile.writeDataLine(writeStream, "Temperature", Temperature, nLevel + 1); writeFile.writeDataLine(writeStream, "HorizontalCoefficient", HorizontalCoefficient, nLevel + 1); writeFile.writeDataLine(writeStream, "VerticalCoefficient", VerticalCoefficient, nLevel + 1); writeFile.writeDataLine(writeStream, "ResistanceCoefficient", ResistanceCoefficient, nLevel + 1); // CFace if (Face != null) { Face.writeObject(writeStream, nLevel + 1); } writeFile.writeEndLine(writeStream, "Coil", nLevel); } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } return(true); }
/// <summary> /// Point Control 은 추가나 삭제가 가능하다. /// 따라서 각 Point Control 의 순번을 List 안에서의 번호를 일치시킨다. /// /// 추가나 삭제때 꼭 호출이 되어야 한다. /// (단, 추가는 마지막 Point Control 에서만 이루어지도록 해서 순서 변경이 없도록 하였다) /// </summary> private void resetSequence() { try { for (int i = 0; i < this.panelPointControl.Controls.Count; i++) { ((CPointUI)this.panelPointControl.Controls[i]).Sequence = this.panelPointControl.Controls.Count - i; } } catch (Exception ex) { CNotice.printLog(ex.Message); } }
internal void restoreMainWindow() { string strCommand; try { strCommand = "main_restore()"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void uploadSettingData() { try { textBoxWorkingDirectory.Text = CSettingData.m_strBaseWorkingDirPath; textBoxFemmPath.Text = CSettingData.m_strFemmExeFileFullName; textBoxMeshSizePercent.Text = CSettingData.m_dMeshLevelPercent.ToString(); comboBoxLanguage.Text = CSettingData.m_emLanguage.ToString(); } catch (Exception ex) { CNotice.printLog(ex.Message); } }
private void downloadSettingData() { try { CSettingData.m_strBaseWorkingDirPath = textBoxWorkingDirectory.Text; CSettingData.m_strFemmExeFileFullName = textBoxFemmPath.Text; CSettingData.m_dMeshLevelPercent = Double.Parse(textBoxMeshSizePercent.Text); CSettingData.m_emLanguage = (EMLanguage)Enum.Parse(typeof(EMLanguage), comboBoxLanguage.Text); } catch (Exception ex) { CNotice.printLog(ex.Message); } }
public void addBoundaryConditon() { string strCommand; try { strCommand = "mi_addboundprop(" + m_strBC + ",0,0,0,0,0,0,0,0,3)"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public static bool checkPreviousFEMM() { try { // FEMM 설치 메인 디렉토리를 얻어낸다. string strFEMMDirName = Path.GetDirectoryName(CSettingData.m_strFemmExeFileFullName); strFEMMDirName = strFEMMDirName.Remove(strFEMMDirName.IndexOf("bin")); // readme.txt 의 첫 줄을 읽어낸다. string strReadmeFileFullName = Path.Combine(strFEMMDirName, "readme.txt"); CReadFile readFile = new CReadFile(); string strVersionFEMM = readFile.getLine(strReadmeFileFullName, 1); // 내용 : FEMM 4.2 12Jan2016 // readme.txt 에서 FEMM 4.2 버전의 Build 날짜를 읽어낸다. char[] separators = { ' ' }; string[] strArray; strArray = strVersionFEMM.Split(separators, StringSplitOptions.None); string strVersionDate = strArray[2]; // 내용 : 12Jan2016 if (strVersionDate.Length < 9) { CNotice.printLogID("TWAP4"); return(false); } DateTime currentDataTime = new DateTime(); DateTime limitDataTime = new DateTime(); limitDataTime = Convert.ToDateTime("24Sep2017"); currentDataTime = Convert.ToDateTime(strVersionDate); // 24Sep2017 보다 이전 버전이면 true 를 리턴한다. if (currentDataTime < limitDataTime) { return(true); } else { return(false); } } catch (Exception ex) { CNotice.printLog(ex.Message); return(false); } }
public void drawLine(double x1, double y1, double x2, double y2, EMMoving emMoving = EMMoving.FIXED) { string strCommand; float fX1, fY1, fX2, fY2; fX1 = (float)x1; fY1 = (float)y1; fX2 = (float)x2; fY2 = (float)y2; try { /// Line 을 추가한다 strCommand = "mi_addnode(" + fX1.ToString() + "," + fY1.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_addnode(" + fX2.ToString() + "," + fY2.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_addsegment(" + fX1.ToString() + "," + fY1.ToString() + "," + fX2.ToString() + "," + fY2.ToString() + ")"; sendCommand(strCommand); /// 그룹을 지정하는 경우만 변경을 한다. if (emMoving == EMMoving.MOVING) { /// 그룹 설정 /// - Point 의 선택이 좌표계산 없이 바로 가능함 /// - 또한 Point 만 그룹을 지정해도 이동이 가능하기 때문에 Point 만 설정함 strCommand = "mi_selectnode(" + fX1.ToString() + "," + fY1.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_selectnode(" + fX2.ToString() + "," + fY2.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_setgroup(" + MOVING_GROUP_NUM.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_clearselected()"; sendCommand(strCommand); } } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void refreshView() { string strCommand; try { /// refresh 를 꼭 해야 색상이 변한다 strCommand = "mi_refreshview()"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void closePost() { string strCommand; try { /// refresh 를 꼭 해야 색상이 변한다 strCommand = "mo_close()"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void closePre() { string strCommand; try { /// nodes, segments, arcsegments, blocks, group strCommand = "mi_close()"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void lockEdit() { string strCommand; // edit 모드를 group 으로 지정해서 마우스 동작을 막는다. try { /// nodes, segments, arcsegments, blocks, group strCommand = "mi_seteditmode(\"group\")"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void addMaterial(string strMaterial) { string strCommand; strMaterial = "\"" + strMaterial + "\""; try { strCommand = "mi_getmaterial(" + strMaterial + ")"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }
public void addCircuitProp(string strCircuit, double dCurrent) { string strCommand; try { strCircuit = "\"" + strCircuit + "\""; // 마지막 파라메타 1 은 Serial 방식으로 추후 Turns 입력이 필요한다. strCommand = "mi_addcircprop(" + strCircuit + "," + dCurrent.ToString() + ",1)"; sendCommand(strCommand); } catch (Exception ex) { CNotice.printLog(ex.Message); return; } }