void AspMainTest::TestContactSpotProcess(MainFrame * frame, AspMainTool *tool){ auto unitMap = tool->product->GetUnitMap(); auto view = frame->myViewer; Standard_Real Gap = 0.5; Handle_AIS_InteractiveContext context = view->getIC(); if (context->HasOpenedContext()) context->CloseAllContexts(); context->EraseAll(true); Standard_Integer curLC = context->OpenLocalContext(); for (auto iter = unitMap->begin(); iter != unitMap->end(); iter++){ Part *part = dynamic_cast<Part *>(iter->second); auto subItr = iter; for (++subItr; subItr != unitMap->end(); subItr++){ Part *obstacle = dynamic_cast<Part *>(subItr->second); //========================================== // Visualise current Parts context->ClearLocalContext(AIS_ClearMode::AIS_CM_Interactive); Handle_AIS_Shape shape = tool->mapOfShapes.find(part->GetUri())->second; context->LocalContext()->Display(shape, AIS_Shaded); context->SetTransparency(shape, 0.2, false); shape = tool->mapOfShapes.find(obstacle->GetUri())->second;; context->LocalContext()->Display(shape, AIS_WireFrame); view->getView()->Redraw(); //========================================== if (obstacle->BndBox()->Distance(*part->BndBox()) < Gap) for (auto &sp : *part){ if (sp.myBox.Distance(*obstacle->BndBox())<Gap) for (auto &obstSp : *obstacle){ if (sp.myBox.Distance(obstSp.myBox)>Gap) continue; //========================================== // Visualise current surface context->ClearLocalContext(AIS_ClearMode::AIS_CM_Interactive); tool->ShowSurface(context, sp); tool->ShowSurface(context, obstSp); view->getView()->Redraw(); //========================================== //========================================== // Launch function Contact Spot if (asp::DBGBuilder::NotInContact(sp, obstSp, 1, Gap)) continue; ContactSpot spot(sp, obstSp, part, obstacle); if (spot.IsDone()){ //========================================== auto vecArray1 = spot.getF1ContactAxis(); auto vecArray2 = spot.getF2ContactAxis(); if (vecArray1.size() && vecArray2.size()){ for (auto &dir : vecArray1){ Handle_ISession_Direction axis = new ISession_Direction(dir.Location(), dir.Direction(), 10); context->LocalContext()->Display(axis, AIS_WireFrame); } for (auto &dir : vecArray2){ Handle_ISession_Direction axis = new ISession_Direction(dir.Location(), dir.Direction(), 10); context->LocalContext()->Display(axis, AIS_WireFrame); } view->getView()->Redraw(); } //} } } } } } context->CloseLocalContext(curLC); }
void AspMainTest::TestIsoFaceForPartCalculation(MainFrame* frame, AspMainTool *tool){ auto aView = frame->myViewer; Handle_AIS_InteractiveContext context = frame->myViewer->getIC(); std::vector<Part *> selectedParts = tool->GetSelectedPart(context); if (selectedParts.size()<2) return; /*auto &PartMap = */selectedParts[0]->UnitMap; AssemblyGraphBuilder builder; //auto NewPart = Part(*(selectedParts[0])); //for (new) auto p1G = builder.GetPartGraphsSet(selectedParts[0],false); auto p2G = builder.GetPartGraphsSet(selectedParts[1], false); std::vector<PartIsomorphism> res; bool result; bool isReversed = false; if (p1G.first.vertex_set().size() > p2G.first.vertex_set().size() || p1G.second.vertex_set().size() > p2G.second.vertex_set().size()) { result = builder.IsomorphismOfPartCompare(p2G, p1G, &res); isReversed= true; } else{ result = builder.IsomorphismOfPartCompare(p1G, p2G, &res); } context->ClearSelected(false); if(!result) return; context->EraseAll(); context->OpenLocalContext(true, true); if (!isReversed){ res[0].isoPart.first = selectedParts[0]->GetUri(); res[0].isoPart.second = selectedParts[1]->GetUri(); } else{ res[0].isoPart.first = selectedParts[1]->GetUri(); res[0].isoPart.second = selectedParts[0]->GetUri(); } _int cColor=0; for (auto &iso : res){ auto partIter= std::find_if(selectedParts.begin(), selectedParts.end(),[&iso](Part* p)->bool{return iso.isoPart.first==p->GetUri();}); auto coPartIter = std::find_if(selectedParts.begin(), selectedParts.end(), [&iso](Part* p)->bool{return iso.isoPart.second == p->GetUri(); }); auto end = selectedParts.end(); if (partIter == end && coPartIter == end) continue; auto FaceSetEnd = iso.isoFaceSet.end(); for (auto &surfP1: *(*partIter)){ auto surfP1Uri = surfP1.uri; auto isoFacesPair = find_if(iso.isoFaceSet.begin(), FaceSetEnd, [&surfP1Uri](std::pair<FaceUri, FaceUri> &f)-> bool { return f.first == surfP1Uri; }); if (isoFacesPair == FaceSetEnd) continue; auto surfP2Uri = isoFacesPair->second; auto &coPartSurfCol = (*coPartIter)->colOfSurf; auto surfP2 = find_if(coPartSurfCol.begin(), coPartSurfCol.end(), [&surfP2Uri](const SurfaceAttribute &att)->bool{return att.uri==surfP2Uri;}); if (surfP2 == coPartSurfCol.end()) continue; Handle_AIS_Shape S1 = new AIS_Shape(surfP1.surf.Face()); Handle_AIS_Shape S2 = new AIS_Shape(surfP2->surf.Face()); Quantity_Color shapeColor = Color::name(++cColor); _int DisplayMode= AIS_Shaded; context->LocalContext()->Display(S1, DisplayMode); context->LocalContext()->Display(S2, DisplayMode); context->SetColor(S1, shapeColor.Name(), false); context->SetColor(S2, shapeColor.Name(), false); } } aView->Update(); }