#pragma execution_character_set("utf-8") #include "Stdafx.h" #include "DllImportOccModeling.h" //#include "OCCViewer.h" #include "ScBRepLib.h" //#include "OffsetGenerate.h" #include "OffsetGenerate1.h" #include #include "gp_Trsf.hxx" #include "DataDefine.h" #include "BaseAlgo.h" #include #include #include #include //OCCViewer myOCCViewer; extern OCCStructDataMD dataMD; namespace OCCModeling { /*******************************************Display ***************************************/ //初始化数据 DLLEXPORT void ReInitData() { dataMD.InitList(); Cal.Init(); } DLLEXPORT BOOL AddObjAppendage(int cmdID, vector order, vector &apd) { int norder = order.size(); int napd = apd.size(); bool bfindcurobj = false; for (int i = 0; i < norder; i++) { int curobjid = order[i]; if (napd > 0 && bfindcurobj == false) { for (int di = 0; di < napd; di++) { if (apd[di].ID == curobjid) { if (dataMD.CheckAppendage(cmdID, apd[di]) == TRUE) { bfindcurobj = true; break; } else { return FALSE; } break; } } } } return TRUE; } DLLEXPORT OCCStructDataMD *GetDataMD() { return &dataMD; } DLLEXPORT BOOL AddObjSpace(int cmdID, vector order, vector &sp) { int norder = order.size(); int ns = sp.size(); bool bfindcurobj=false; for (int i = 0; i < norder; i++) { int curobjid = order[i]; if (ns > 0 && bfindcurobj == false) { for (int di = 0; di < ns; di++) { if (sp[di].ID == curobjid) { if (dataMD.CheckSpace(cmdID, sp[di]) == TRUE) { bfindcurobj = true; break; } else { return FALSE; } break; } } } } return TRUE; } DLLEXPORT BOOL AddObjHull(int cmdID, vector order, vector &hull) // int norder, int order[] ,) { int norder = order.size(); int nh = hull.size(); bool bfindcurobj=false; for (int i = 0; i < norder; i++) { int curobjid = order[i]; if (nh > 0 && bfindcurobj == false) { for (int di = 0; di < nh; di++) { if (hull[di].ID == curobjid) { // if(dataMD.m_mapShellSurf.find(curobjid)!=dataMD.m_mapShellSurf.end()) //{ // dataMD.DelObj(cmdID,curobjid); //} if (dataMD.CheckHull(cmdID, hull[di]) == TRUE) { bfindcurobj = true; // dataMD.ShellHydrostaticCalculation(); break; } else { // dataMD.errorinfo="添加外板面图元失败 "; return FALSE; } break; } } } } return TRUE; } //���Ӽ������ DLLEXPORT BOOL AddCalObj(int cmdID,int norder, int order[] , int ndel, int del[], int npnts, Point3D pnts[], int npnt, HydroInletPoint pnt[], int ncrv, HydroLimitAng ang[],int nmargin, MarginLine marginpnts[], int nopen, ImmersionOpen opens[]) { int curobjid; bool bfindcurobj=false; if(norder>0) { if(npnts>0 && bfindcurobj==false)//点处理过程验证加生成 { for(int pi=0;pi 0) { //先删除进水点,然后重新添加 vector ivec; map::iterator it=dataMD.m_mapInletPoint.begin(); for (; it!=dataMD.m_mapInletPoint.end();it++ ) { //dataMD.DelObj(-1,it->first); ivec.push_back(it->first); } for (vector::size_type ix = 0; ix != ivec.size(); ++ix) { dataMD.DelObj(-1,ivec[ix]); } } if (ncrv > 0) { //先删除静倾角,然后重新添加 vector ivec; map::iterator it=dataMD.m_mapLimitAng.begin(); for (; it!=dataMD.m_mapLimitAng.end();it++ ) { //dataMD.DelObj(-1,it->first); ivec.push_back(it->first); } for (vector::size_type ix = 0; ix != ivec.size(); ++ix) { dataMD.DelObj(-1,ivec[ix]); } } if (nmargin > 0) { vector ivecm; map::iterator it = dataMD.m_mapMarginLine.begin(); for (;it!=dataMD.m_mapMarginLine.end();it++) ivecm.push_back(it->first); for (vector::size_type ix = 0; ix != ivecm.size(); ++ix) { dataMD.DelObj(-1,ivecm[ix]); } } if (nopen > 0) { vector iveco; map::iterator it = dataMD.m_mapImmersionOpen.begin(); for (;it!=dataMD.m_mapImmersionOpen.end();it++) iveco.push_back(it->first); for (vector::size_type ix = 0; ix != iveco.size(); ++ix) { dataMD.DelObj(-1,iveco[ix]); } } for(int i=0;i< norder;i++) { curobjid=order[i]; bfindcurobj=false; if(npnt>0 && bfindcurobj==false)//静水力点处理过程验证加生成 { for(int pi=0;pi0 && bfindcurobj==false)//线处理过程 { for(int ci=0;ci0 && bfindcurobj==false)//限界线 { if(dataMD.AddMarginLine(nmargin,marginpnts[0])==TRUE) { bfindcurobj=true; break; } //for(int pi=0;pi0 && bfindcurobj==false)//浸水开口 { for(int pi=0;pi0 && bfindcurobj==false)//删除处理过程 { for(int deli=0;deli order, vector& pnt, vector& crv, vector& srf, vector& sld /*int norder, int order[] , int ndel, int del[], int npnt,Point3D pnt[], int ncrv,Curve crv[], int nsrf,Surface srf[], int nsld,Solid sld[], int nmds, MainDeckSurf mds[], int nss, ShellSurf ss[], int nds, DeckSurf ds[], int nbs, BoundSurf bs[], int nsds, SubdivSurf sds[], int nocr, OpenCargoRegion ocr[], int nsp, Space sp[], int napd, Appendage apd[], int nh, Hull h[], int nrenameObj, RenameObject renameObj[]*/ ) { int curobjid; bool bfindcurobj=false; int norder = order.size(); int npnt = pnt.size(); int ncrv = crv.size(); int nsrf = srf.size(); int nsld = sld.size(); if(norder>0) { for(int i=0;i< norder;i++) { curobjid=order[i]; bfindcurobj=false; //点处理过程验证加生成 if(npnt>0 && bfindcurobj==false) { for(int pi=0;pi0 && bfindcurobj==false) { for(int ci=0;ci0 && bfindcurobj==false) { for(int si=0;si0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int di=0;di0 && bfindcurobj==false) { for(int deli=0;deli order, vector del ) { int norder=order.size(); int ndel=del.size(); bool bfindcurobj=false; for(int i=0;i0 && bfindcurobj==false) { for(int di=0;di order, vector& pnt, vector& crv, vector& srf, vector& sld /*int norder, int order[] , int ndel, int del[], int npnt,Point3D pnt[], int ncrv,Curve crv[], int nsrf,Surface srf[], int nsld,Solid sld[], int nmds, MainDeckSurf mds[], int nss, ShellSurf ss[], int nds, DeckSurf ds[], int nbs, BoundSurf bs[], int nsds, SubdivSurf sds[], int nocr, OpenCargoRegion ocr[], int nsp, Space sp[], int napd, Appendage apd[], int nh, Hull h[], int nrenameObj, RenameObject renameObj[]*/ ) { // // EnterCriticalSection(&myOCCViewer.m_CS); // BOOL ret = AddObjPriv(cmdID,norder, order, // ndel, del, // npnt, pnt, // ncrv, crv, // nsrf, srf, // nsld, sld, // nmds, mds, // nss, ss, // nds, ds, // nbs, bs, // nsds, sds, // nocr, ocr, // nsp, sp, // napd, apd, // nh, h, // nrenameObj, renameObj // ); bool ret = AddObjPriv(cmdID, order, pnt, crv, srf,sld); // LeaveCriticalSection(&myOCCViewer.m_CS); return ret; } DLLEXPORT bool InitCalData(int npnt, HydroInletPoint pnt[], int ncrv, HydroLimitAng ang[], int nmargin, MarginLine marginpnts[],int nopen, ImmersionOpen opens[]) { if(npnt>0 )//进水点处理过程 { for(int si=0;si0 )//极限静倾角处理过程 { for(int si=0;si0 )//限界线处理过程 { for(int si=0;si0 )//浸水开口处理过程 { for(int si=0;si& h, vector& sp, vector& apd ) { int nh = h.size(); int nsp = sp.size(); int napd = apd.size(); if(nh>0)//主船体 { for(int di=0;di0)//舱室 { for(int di=0;di0)//附体 { for(int di=0;di& pnt, vector& crv, vector& srf, vector& sld /*, int nsrf, Surface srf[], int nsld, Solid sld[], int nmds, MainDeckSurf mds[], int nss, ShellSurf ss[], int nds, DeckSurf ds[], int nbs, BoundSurf bs[], int nsds, SubdivSurf sds[], int nocr, OpenCargoRegion ocr[], int nsp, Space sp[], int napd, Appendage apd[], int nh, Hull h[]*/ ) { int npnt = pnt.size(); int ncrv = crv.size(); int nsrf = srf.size(); int nsld = sld.size(); if(npnt>0) { for(int pi=0;pi0 )//线处理过程 { for(int ci=0;ci0 )//面处理过程 { for(int si=0;si0 )//体处理过程 { for(int di=0;di0 )//主甲板面 { for(int di=0;di0)//外板面 { for(int di=0;di0)//主船体 { for(int di=0;di0)//平台面 { for(int di=0;di0)//上建外围面 { for(int di=0;di0)//分舱面 { for(int di=0;di0)//开敞客货区`` { for(int di=0;di0)//舱室 { for(int di=0;di0)//附体 { for(int di=0;di0) { for(int i=0;i /// 上甲板ID /// 折角线ID /// 舭部是否升高 /// 舭部升高值(m) /// 船型 /// 是否非对称船型 /// 返回型值表对应ID /// 每个ID对应PNTS中的长度 /// 型值点数组 DLLEXPORT int GetOffsetTableData(int upperDeckID, int foldingLinesID[], int isBilge, double BilgeHC, int shiptype, int asymmetricType, int ids[], int lens[], OffsetTablePoint *pnts) { OffsetGenerate1 offger; return offger.GetOffsetTableData(upperDeckID,foldingLinesID,isBilge,BilgeHC,shiptype,asymmetricType,ids,lens,pnts); } /********************************* Check *********************************************/ BOOL CheckPointPriv(Point3D *pnt) { if(pnt->Type ==0)//普通点 { return dataMD.CheckSimplePoint(pnt); } else if(pnt->Type ==1)//线上点 { return dataMD.CheckOnLinePoint(pnt); } else if(pnt->Type ==2)//交点 { return dataMD.CheckCrossPoint(pnt); } else if(pnt->Type ==3)//线面交点 { return dataMD.CheckLineFacePoint(pnt); } else if(pnt->Type ==9)//镜像点认为是普通点 //20161228 by czb { return dataMD.CheckSimplePoint(pnt); } else if(pnt->Type ==10)//引用线上节点C/N=? { return dataMD.CheckLineRefPoint(pnt); } else if(pnt->Type ==11)//实体点对应的点 //20170501 by czb { return dataMD.CheckSimplePoint(pnt); } else { dataMD.errorinfo="无法生成此类点图元 "; return FALSE; } return TRUE; } DLLEXPORT BOOL CheckPoint(Point3D *pnt) { // EnterCriticalSection(&myOCCViewer.m_CS); bool b = CheckPointPriv(pnt); // LeaveCriticalSection(&myOCCViewer.m_CS); return b; } DLLEXPORT const char* GetErrInfo() { return dataMD.errorinfo.c_str(); } /***************************************** Interaction *****************************************/ DLLEXPORT double GetS(int id) { return dataMD.GetS(id); } DLLEXPORT double GetV(int id) { return dataMD.GetV(id); } DLLEXPORT double GetTonnageV1() { return dataMD.GetTonnageV1(); } DLLEXPORT bool SaveTopoToStep(char* path,int ids[]) { return dataMD.SaveTopoToStep(path,ids); } //20161227 by czb,新增 DLLEXPORT bool SaveTopoToStep2(char* path) { return dataMD.SaveTopoToStep2(path); } //20161214 by czb,新增 DLLEXPORT void GetOCIDXOfTopo(int ids[]) { return dataMD.GetOCIDXOfTopo(ids); } DLLEXPORT bool SaveTopoToBrep(char* path) { return dataMD.SaveTopoToBrep(path); } DLLEXPORT bool LoadTopoFromStep(char* path,QVector ids) { return dataMD.LoadTopoFromStep(path,ids); } DLLEXPORT bool CreateInterHullXml() { //实现1计算接口 //从数据结构中找到船壳,按配置文件中设置的z的间隔进行剪切获得属性 设置的z在 /*if (type == 1) {*/ //Cal.CreateHull(); //Cal.CreateCalXML(); //Cal.CreateSectionXML(); //Cal.CreateHeelHullXML(); //Cal.CreateTrimXML(); return true; // }else if (type == 2) //{ // if (Cal.topoSolid.IsNull()) // CreateHull(); } DLLEXPORT bool CreateHullSolid() { //Cal.CreateHull(); return true; } DLLEXPORT bool CreateInterCompXml() { //Cal.CreateCompCalXML(); return true; } DLLEXPORT bool SetCompartmentPara(int ComID,int CStatus) { //Cal.SetCompPara(ComID,CStatus); return true; } DLLEXPORT int GetMarginLineleData(int lens[], OffsetTablePoint *pnts) { OffsetGenerate1 offger; return offger.GetMarginLineleData(lens, pnts); } DLLEXPORT bool CreateCXml() { //Cal.CreateHull(); //Cal.CreateProfileCalXML(); return true; } DLLEXPORT double GetImmersionOpenPos(double X, double Y, double oppositZ) { return dataMD.GetImmersionOpenPos(X, Y, oppositZ); } DLLEXPORT bool SetHullPara(int zCnt,double zStep[],int xCnt,double xStep[],int heelCnt,double heelStep[],double heelC[], double heelFMax,double heelFMin,double heelDai,int trimCnt,double trimStep[], double trimFMax,double trimFMin,double trimDai,int startType) { vector zVec; vector xVec; vector heelVec; vector trimVec; vector heelCVec; bool bShell = dataMD.m_mapMainDeckSurf.size()==1 && dataMD.m_mapShellSurf.size()==1; TopoDS_Shape solid;// = dataMD.CreateHull(); for(int i = 0; i < zCnt; i++) { zVec.push_back(zStep[i]); } for(int i = 0; i < xCnt; i++) { xVec.push_back(xStep[i]); } for(int i = 0; i < heelCnt; i++) { heelVec.push_back(heelStep[i]); heelCVec.push_back(heelC[i]); } for(int i = 0; i < trimCnt; i++) { trimVec.push_back(trimStep[i]); } bool bZstep = Cal.CheckZStep(zVec); bool bXstep = Cal.CheckXStep(xVec); bool bHeel = Cal.CheckHeel(heelVec, heelCVec, heelFMax, heelFMin, heelDai); bool bTrim = Cal.CheckTrim(trimVec, trimFMax, trimFMin, trimDai); //写xml if(!bZstep) { dataMD.SetCalParaXml("ZSTEP", zVec); } if(!bXstep) { dataMD.SetCalParaXml("XSTEP", xVec); } if(!bHeel) { dataMD.SetCalParaXml("HEEL", heelVec, heelCVec, heelFMax, heelFMin, heelDai); } if(!bTrim) { dataMD.SetCalParaXml("TRIM", trimVec, trimFMax, trimFMin, trimDai); } //水平切 if(!bZstep) { Cal.SetZStep(zVec); if(startType) { processCal.StartProcessCal(0, solid, 0); } } //横剖切 if(!bXstep) { Cal.SetXStep(xVec); if(startType) { processCal.StartProcessCal(1, solid, 0); processCal.StartProcessCal(4, solid, 0); } } else if(!bZstep) { if(startType) { processCal.StartProcessCal(1, solid, 0); } } //水平旋转切 if(!bHeel) { Cal.SetHeel(heelVec, heelCVec,heelFMax, heelFMin, heelDai); if(startType) { processCal.StartProcessCal(2, solid, 0); } } //横剖旋转切 if(!bTrim) { Cal.SetTrim(trimVec, trimFMax, trimFMin, trimDai); if(startType) { processCal.StartProcessCal(3, solid, 0); } } return true; } DLLEXPORT void LoadCalculationXML(char* path) { //dataMD.LoadCalculationXML(path); } DLLEXPORT void SaveCalculationXML(char* path) { //dataMD.SaveCalculationXML(path); } DLLEXPORT void CloseCalulation() { dataMD.CloseCalculation(); } //进水点计算接口 DLLEXPORT void SetInletPoint(int delpnts,Point3D delpnt[],int addpnts,Point3D addpnt[], int updCnt, int oldIDs[], Point3D newIDs[]) { dataMD.SetInletPoint(delpnts, delpnt, addpnts, addpnt, updCnt, oldIDs, newIDs); } //极限静倾角计算接口 DLLEXPORT void SetDeckBilgePoint(int Cnt, Point3D addDeck[], Point3D addBilge[]) { dataMD.SetDeckBilgePoint(Cnt, addDeck, addBilge); } //导出船壳计算数据文件 DLLEXPORT bool ExportHullCalFile(string fileName, string path, vector& hullIDs) { return dataMD.ExportHull(fileName, path, hullIDs); } //导出舱室计算数据文件 DLLEXPORT bool ExportSpaceCalFile(string fileName, string path, vector&spaceIDs) { return dataMD.ExportSpace(fileName, path, spaceIDs); } //导出舱室计算数据文件 DLLEXPORT bool ExportSolidCalFile(char* fileNameWithExtension, char* path, int count, int ids[])//20190601 added by czb { return dataMD.ExportSolidSTL(fileNameWithExtension, path, count, ids); } //导出计算数据文件 //DLLEXPORT void ExportIGES(char* fileName) //{ // dataMD.ExportIGES(fileName); //} //获取曲线首尾端点和肋位或站位点 type=1,肋位;type=2,站位 DLLEXPORT int GetCurvePointByFS(int curveID, int xlen, double xSet[], int lens[], Point3D *pnts) { return dataMD.GetCurvePointByFS(curveID, xlen, xSet, lens, pnts); } DLLEXPORT int GetCurvePointByFSEx(int curveID, int xlen, vector& xSet,vector& pnts) { return dataMD.GetCurvePointByFSEx(curveID, xlen, xSet, pnts); } // 数据接口 Lvxj //导入型值表文件 DLLEXPORT void ImportOffsetData(bool bImportCtrlPnt,float xSubSectionLen) { dataMD.ImportOffsetData(bImportCtrlPnt,xSubSectionLen); } //导出型值表文件 DLLEXPORT void ExportOffsetData(double* shipSize,double* expParam, int* expType) { dataMD.ExportOffsetData(shipSize,expParam,expType); } //导入CAD文件 DLLEXPORT void ImportCAD(char* fileName) { dataMD.ImportCAD(fileName); } //导入IGES文件 DLLEXPORT long ImportIGES(char* fileName, int impType, float*transfromParams) { return dataMD.ImportIGES(fileName,impType,transfromParams); } //转换CAD型线 DLLEXPORT void TransfCADLine(int selectedCnt, int* selectLst, int lineType, float* fCADPar,int lens[], Point3D *pnts) { dataMD.TransfCADLine(selectedCnt, selectLst, lineType, fCADPar,lens, pnts); } //计算两条线交点 DLLEXPORT int GetIntersectPnt(int selectedCnt, int* selectLst,double*pPnt) { return dataMD.GetIntersectPnt(selectedCnt, selectLst,pPnt); } //导出IGES文件 DLLEXPORT void ExportIGES(char* fileName,int expOption,int selectCnt,int*selectLst) { dataMD.ExportIGES(fileName,expOption,selectCnt,selectLst); } DLLEXPORT bool SetObjVisibel(std::vector& ids,int value) { for (auto id :ids) { SetObjVisibel(id,value); } return true; } DLLEXPORT bool SetObjVisibel(int id,int value) { double type = id / MAX_SIZE_OF_OBJECT_GROUP; if (type < 1) { for (auto &it : dataMD.m_mapPoints) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 1 && type < 2) { for (auto &it : dataMD.m_mapCurves) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 2 && type < 3) { for (auto &it : dataMD.m_mapSurfaces) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 3 && type < 4) { for (auto &it : dataMD.m_mapSolids) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 10 && type < 11) { } else if (type >= 11 && type < 12) { } else if (type >= 12 && type < 13) { } else if (type >= 13 && type < 14) { } else if (type >= 14 && type < 15) { } else if (type >= 15 && type < 16) { } else if (type >= 16 && type < 17) { for (auto &it : dataMD.m_mapSpace) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 17 && type < 18) { for (auto &it : dataMD.m_mapAppendage) { if (it.second.ID == id) { it.second.Visible = value; break; } } } else if (type >= 18 && type < 19) { for (auto &it : dataMD.m_mapHull) { if (it.second.ID == id) { it.second.Visible = value; break; } } } return true; } }