/** * Function TestLineChainEqualCPolyLine * tests the equality between a SHAPE_LINE_CHAIN polygon and a polygon inside a * CPolyLine object using Boost test suite. * @param lineChain is a SHAPE_LINE_CHAIN polygon object. * @param polyLine is a CPolyLine polygon object. * @param contourIdx is the index of the contour inside polyLine that has to be tested * against lineChain. */ void TestLineChainEqualCPolyLine(SHAPE_LINE_CHAIN& lineChain, CPolyLine& polyLine, int contourIdx = 0) { // Arrays to store the polygon points lexicographically ordered std::vector<VECTOR2I> chainPoints; std::vector<VECTOR2I> polyPoints; // Populate the array storing the new data with the lineChain corners for (int pointIdx = 0; pointIdx < lineChain.PointCount(); pointIdx++) { chainPoints.push_back(lineChain.Point(pointIdx)); } int start = polyLine.GetContourStart(contourIdx); int end = polyLine.GetContourEnd(contourIdx); // Populate the array storing the legacy data with the polyLine corners for (int pointIdx = start; pointIdx <= end; pointIdx++) { polyPoints.push_back( VECTOR2I(polyLine.GetX(pointIdx), polyLine.GetY(pointIdx)) ); } // Order the vectors in a lexicographic way std::sort(chainPoints.begin(), chainPoints.end(), lexicographicOrder); std::sort(polyPoints.begin(), polyPoints.end(), lexicographicOrder); // Compare every point coordinate to check the equality BOOST_CHECK_EQUAL_COLLECTIONS(chainPoints.begin(), chainPoints.end(), polyPoints.begin(), polyPoints.end()); }
void POINT_EDITOR::removeCorner( EDIT_POINT* aPoint ) { EDA_ITEM* item = m_editPoints->GetParent(); if( item->Type() == PCB_ZONE_AREA_T ) { const SELECTION& selection = m_selectionTool->GetSelection(); PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>(); ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item ); CPolyLine* outline = zone->Outline(); for( int i = 0; i < outline->GetCornersCount(); ++i ) { if( VECTOR2I( outline->GetPos( i ) ) == aPoint->GetPosition() ) { frame->OnModify(); frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); outline->DeleteCorner( i ); setEditedPoint( NULL ); break; } } } }
/** * Function NormalizeAreaOutlines * Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s) * @param aNewPolygonList = a std::vector<CPolyLine*> reference where to store new CPolyLine * needed by the normalization * @return the polygon count (always >= 1, because there is at least one polygon) * There are new polygons only if the polygon count is > 1 */ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList ) { SHAPE_POLY_SET polySet = ConvertPolyListToPolySet( m_CornersList ); // We are expecting only one main outline, but this main outline can have holes // if holes: combine holes and remove them from the main outline. // Note also we are using SHAPE_POLY_SET::PM_STRICTLY_SIMPLE in polygon // calculations, but it is not mandatory. It is used mainly // because there is usually only very few vertices in area outlines SHAPE_POLY_SET::POLYGON& outline = polySet.Polygon( 0 ); SHAPE_POLY_SET holesBuffer; // Move holes stored in outline to holesBuffer: // The first SHAPE_LINE_CHAIN is the main outline, others are holes while( outline.size() > 1 ) { holesBuffer.AddOutline( outline.back() ); outline.pop_back(); } polySet.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE); // If any hole, substract it to main outline if( holesBuffer.OutlineCount() ) { holesBuffer.Simplify( SHAPE_POLY_SET::PM_FAST); polySet.BooleanSubtract( holesBuffer, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } RemoveAllContours(); // Note: we can have more than outline, because a self intersecting outline will be // broken to non intersecting polygons, and removing holes can also create a few polygons for( int ii = 0; ii < polySet.OutlineCount(); ii++ ) { CPolyLine* polyline = this; if( ii > 0 ) { polyline = new CPolyLine; polyline->ImportSettings( this ); aNewPolygonList->push_back( polyline ); } SHAPE_POLY_SET pnew; pnew.NewOutline(); pnew.Polygon( 0 ) = polySet.CPolygon( ii ); polyline->m_CornersList = ConvertPolySetToPolyList( pnew ); } return polySet.OutlineCount(); }
// Create CPolyLine for a pad // CPolyLine * CPolyLine::MakePolylineForPad( int type, int x, int y, int w, int l, int r, int angle ) { CPolyLine * poly = new CPolyLine; int dx = l/2; int dy = w/2; if( angle%180 == 90 ) { dx = w/2; dy = l/2; } if( type == PAD_ROUND ) { poly->Start( 0, 0, 0, x-dx, y, 0, NULL, NULL ); poly->AppendCorner( x, y+dy, ARC_CW, 0 ); poly->AppendCorner( x+dx, y, ARC_CW, 0 ); poly->AppendCorner( x, y-dy, ARC_CW, 0 ); poly->Close( ARC_CW ); } return poly; }
int CGIS_VectorData::ReadFromFile() { ifstream vecinfile("VectorDataOutput.data", ifstream::in); vecinfile>>_npolylines; // cout<<"\n\n npolylines="<<_npolylines<<endl; for(int j=0; j<_npolylines; ++j){ CPolyLine *pl = new CPolyLine(); _polylines.push_back(pl); // cout<<"#############"<<endl; pl->ReadPolyLine(&vecinfile); } vecinfile.close(); return 0; }
//----------------------------------------------------------------------------------------- TestTransformation::TestTransformation() : m_bPressed(false) , m_bTouch(false) , m_StartPan(-1, -1) , m_LastPan(-1, -1) { // On cr�e une camera CCamera* pCamera = m_pSceneManager->createCamera(); m_vNewEyePosition = QVector3D(8., 8., 4.); pCamera->setEyePosition(m_vNewEyePosition); pCamera->setCenter(QVector3D(0., 0., 0.)); qDebug() << "Create View"; m_pView = createWidget3D(pCamera); m_pView->setAttribute(Qt::WA_AcceptTouchEvents); qDebug() << "End create View"; // On cr�e un noeud afin d'y placer une lumi�re CSceneNode* pRootNode = getSceneManager()->getRootNode(); // On cr�e une lumi�re diffuse bleue CLight* pLight = getSceneManager()->createLight(); pLight->setDiffuseColor(1.0, 1.0, 1.0); pLight->setAmbientColor(1.0, 1.0, 1.0); pLight->setDirection(QVector3D(-1, 0, 0)); pLight->setSpecularColor(1.0f, 1.0f, 1.0f); // On l'associe au noeud pRootNode->addItem(pLight); // SkyBox CSkyBox* pSkyBoxMesh = CMeshManager::getInstance().createCustomMesh<CSkyBox>("CSkyBox", "SkyBoxMesh"); CMeshInstance* pSkyBox = getSceneManager()->createMeshInstance(pSkyBoxMesh, "SkyBox"); pSkyBox->setSelectable(false); CSceneNode* pSkyBoxNode = pRootNode->createChild("SkyBoxNode"); pSkyBoxNode->scale(400.); pSkyBoxNode->addItem(pSkyBox); CMaterial* pSkyBoxMat = CMaterialManager::getInstance().createMaterial("SkyBoxMaterial"); pSkyBox->setMaterialName(pSkyBoxMat->getName()); QStringList fileNames; fileNames << "://Resources/xpos.png" << "://Resources/xneg.png" << "://Resources/ypos.png" << "://Resources/yneg.png" << "://Resources/zpos.png" << "://Resources/zneg.png"; ATexture* pSkyBoxTexture = CTextureManager::getInstance().createTextureCube("SkyBoxTexCube", fileNames); pSkyBoxMat->addTexture(pSkyBoxTexture, eDiffuse); #ifdef EMBEDDED_TARGET CShader* pShader = CShaderManager::getInstance().createShader( "SkyBoxShader", "://Resources/skyboxES.vertex.glsl", "", "://Resources/skyboxES.fragment.glsl"); #else CShader* pShader = CShaderManager::getInstance().createShader( "SkyBoxShader", "://Resources/skybox.vertex.glsl", "", "://Resources/skybox.fragment.glsl"); #endif pSkyBoxMat->getRenderPass(0)->setShaderName(pShader->getName()); pSkyBoxMat->getRenderPass(0)->renderStates().setFaceCulling(CFaceCulling(false)); // Particules CBillboard* pBillboard = getSceneManager()->createBillboard(); QVector<QVector3D> pos; for (int i = 0; i < 1000; ++i) pos << QVector3D( Math::randDouble(-200., +200.), Math::randDouble(-200., +200.), Math::randDouble(-200., +200.)); pBillboard->addPositions(pos); CMaterial* pBillboardMat = CMaterialManager::getInstance().createMaterial("BillboardMaterial"); pBillboardMat->getRenderPass(0)->renderStates().setFaceCulling(CFaceCulling(false)); CBlending blending; blending.setEnabled(true); blending.setBlendEquation(eAdd, eAdd); blending.setBlendSeparateFunction(Source::eSourceAlpha, Destination::eOneMinusSourceAlpha, Source::eOne, Destination::eZero); pBillboardMat->getRenderPass(0)->renderStates().setBlending(blending); ATexture* pBillboardTexture = CTextureManager::getInstance().createTexture2D("BillBoardTex", "://Resources/particle.png"); pBillboardMat->addTexture(pBillboardTexture, eDiffuse); CShader* pBillboardShader = CShaderManager::getInstance().createShader("BillboardShader", "://Resources/billboard.vertex.glsl", "://Resources/billboard.geometry.glsl", "://Resources/billboard.fragment.glsl"); pBillboardMat->getRenderPass(0)->setShaderName(pBillboardShader->getName()); pBillboard->setMaterialName(pBillboardMat->getName()); pBillboardShader->setUniformValue("halfSize", 1.); CSceneNode* pBillboardNode = pRootNode->createChild("BillboardNode"); pBillboardNode->addItem(pBillboard); // Orbites CPolyLine* pPolyLine = CMeshManager::getInstance().createCustomMesh<CPolyLine>("CPolyLine", "CPolyLine"); QList<QVector3D> pts; for (int i = 0; i <= 360; ++i) { pts << QVector3D(cos(Math::degToRad((real)i)), 0., sin(Math::degToRad((real)i))); } pPolyLine->addPoints(pts); CSphereMesh* pSphereMesh = CMeshManager::getInstance().createCustomMesh<CSphereMesh>("CSphereMesh", "SphereMesh"); CMeshInstance* pSun = getSceneManager()->createMeshInstance(pSphereMesh, "Sun"); CMaterial* pSunMat = CMaterialManager::getInstance().createMaterial("SunMat"); pSunMat->setAmbientColor(1., 1., 1.); CTexture2D* pSunTexture = CTextureManager::getInstance().createTexture2D("SunTex", ":/Resources/sun.png"); pSunMat->addTexture(pSunTexture, eDiffuse); pSun->setMaterialName(pSunMat->getName()); CMeshInstance* pEarth = getSceneManager()->createMeshInstance(pSphereMesh, "Earth"); CMaterial* pEarthMat = CMaterialManager::getInstance().createMaterial("EarthMat"); CTexture2D* pEarthTexture = CTextureManager::getInstance().createTexture2D("EarthTex", ":/Resources/earth.png"); pEarthMat->addTexture(pEarthTexture, eDiffuse); pEarthMat->setAmbientColor(0.1, 0.1, 0.1); pEarthMat->setDiffuseColor(1.0, 1.0, 1.0); pEarthMat->setShininessFactor(10); pEarth->setMaterialName(pEarthMat->getName()); CMeshInstance* pJupiter = getSceneManager()->createMeshInstance(pSphereMesh, "Jupiter"); CMaterial* pJupiterMat = CMaterialManager::getInstance().createMaterial("JupiterMat"); pJupiterMat->setAmbientColor(0.4, 0.4, 0.4); CTexture2D* pJupiterTexture = CTextureManager::getInstance().createTexture2D("JupiterTex", ":/Resources/jupiter.png"); pJupiterMat->addTexture(pJupiterTexture, eDiffuse); pJupiter->setMaterialName(pJupiterMat->getName()); CMeshInstance* pMoon = getSceneManager()->createMeshInstance(pSphereMesh, "Moon"); CMaterial* pMoonMat = CMaterialManager::getInstance().createMaterial("MoonMat"); CTexture2D* pMoonTexture = CTextureManager::getInstance().createTexture2D("MoonTex", ":/Resources/moon.png"); pMoonMat->addTexture(pMoonTexture, eDiffuse); pMoon->setMaterialName(pMoonMat->getName()); CCoordinateSystem* pCoordinateSystemMesh = CMeshManager::getInstance().createCustomMesh<CCoordinateSystem>("CCoordinateSystem", "CCoordinateSystem"); CMeshInstance* pCoordinateSystem = getSceneManager()->createMeshInstance(pCoordinateSystemMesh, "CoordinateSystem"); pRootNode->addItem(pCoordinateSystem); pRootNode->addItem(pSkyBox); m_pSolarSystemNode = pRootNode->createChild(QVector3D(0., 0., 0.)); m_pSunNode = m_pSolarSystemNode->createChild(QVector3D(0., 0., 0.)); m_pSunNode->scale(4.0); m_pSunNode->addItem(pSun); m_pSunToEarthNode = m_pSolarSystemNode->createChild(); m_pSunToJupiterNode = m_pSolarSystemNode->createChild(); CMeshInstance* pSunToEarthPLine = getSceneManager()->createMeshInstance(pPolyLine, "SunToEarth"); pSunToEarthPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pSunToEarthNode->addItem(pSunToEarthPLine); m_pSunToEarthNode->scale(10.0); m_pEarthNode = m_pSolarSystemNode->createChild(QVector3D(10.0, 0., 0.)); m_pEarthNode->scale(1.0); m_pEarthNode->addItem(pEarth); CMeshInstance* pSunToJupiterPLine = getSceneManager()->createMeshInstance(pPolyLine, "SunToJupiter"); pSunToJupiterPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pSunToJupiterNode->addItem(pSunToJupiterPLine); m_pSunToJupiterNode->scale(20); m_pJupiterNode = m_pSolarSystemNode->createChild(QVector3D(20.0, 0., 0.)); m_pJupiterNode->scale(4.0); m_pJupiterNode->addItem(pJupiter); m_pEarthToMoonNode = m_pEarthNode->createChild(); CMeshInstance* pEarthToMoonPLine = getSceneManager()->createMeshInstance(pPolyLine, "EarthToMoon"); pEarthToMoonPLine->setMaterialName(CMaterialManager::getInstance().getMaterialNameByColor(Color::eWhite)); m_pEarthToMoonNode->addItem(pEarthToMoonPLine); m_pEarthToMoonNode->scale(2.0); m_pEarthToMoonNode->rotate(QVector3D(1.0, 0.0, 0.0), 30); m_pMoonNode = m_pEarthToMoonNode->createChild(QVector3D(1.0, 0.0, 0.)); m_pMoonNode->scale(0.2); m_pMoonNode->addItem(pMoon); QTimer* pTimer = new QTimer(this); connect(pTimer, SIGNAL(timeout()), this, SLOT(onTimeout())); pTimer->start(5); connect(m_pView, SIGNAL(mouseMoved()), this, SLOT(onMouseMoved())); connect(m_pView, SIGNAL(mouseReleased()), this, SLOT(onMouseReleased())); connect(m_pView, SIGNAL(mousePressed()), this, SLOT(onMousePressed())); connect(m_pView, SIGNAL(touchScaleStarted()), this, SLOT(onTouchScaleStarted())); connect(m_pView, SIGNAL(touchScaleChanged(real)), this, SLOT(onTouchScaleChanged(real))); connect(m_pView, SIGNAL(touchScaleEnded()), this, SLOT(onTouchScaleEnded())); //m_pView->setGeometry(QRect(1920, 100, 400, 300)); m_GlobalTime.start(); }
int CGIS_VectorData::ReadVectorData() { int status_vec; int nlines; int ltype; int npts; int i, j; double* line_x; double* line_y; string lbl; //Initialize the GIS vector data status_vec = Initialize_Vector_data(_gisDBase, _gisMaplocation, _gisMapset, _gisVectorFile); if(status_vec == 0) { if(Get_vector_n_lines(&nlines)) { cout<<"Error retrieving number of lines from Vector Data"<<endl; return 1; } _npolylines = nlines; for (i = 0; i < _npolylines; i++) { if ( Get_vector_line_type(i, <ype) ) { cout<<"Error retrieving line type from Vector Data"<<endl; return 1; } if (Get_vector_line_size(i, &npts) ) { cout<<"Error retrieving line size from Vector Data"<<endl; return 1; } if (Get_vector_line_label(i, &lbl) ) { cout<<"Error retrieving line label from Vector Data"<<endl; return 1; } // cout<<"in my zone .."<<lbl<<endl; if (npts > 0) { CPolyLine *pl = new CPolyLine(ltype, lbl); _polylines.push_back(pl); line_x = new double[npts]; line_y = new double[npts]; if ( Get_vector_line(i, line_x, line_y) ) { cout<<"Error retrieving XY Vector Data"<<endl; delete [] line_x; delete [] line_y; return 1; } pl->SetLinesXY(npts, line_x, line_y); delete [] line_x; delete [] line_y; } }//for(i) }else{ cout<<"\n\nError Initializing Vector Data : "<<_gisDBase<<":"<<_gisMaplocation<<":"<<_gisMapset<<":"<<_gisVectorFile<<endl; return 1; }//if-else(status_vec == 0) if(Delete_Vector_data()){ cout<<"\n\nERROR: Unable to delete Vector data"; return 1; } cout<<"DONE WITH CGIS_VectorData ReadVectorData()!!"<<endl; return 0; }//ReadVectorData()
// Use the General Polygon Clipping Library to clip contours // If this results in new polygons, return them as CArray p // If bRetainArcs == TRUE, try to retain arcs in polys // Returns number of external contours, or -1 if error // int CPolyLine::NormalizeWithGpc( CArray<CPolyLine*> * pa, BOOL bRetainArcs ) { CArray<CArc> arc_array; if( bRetainArcs ) MakeGpcPoly( -1, &arc_array ); else MakeGpcPoly( -1, NULL ); Undraw(); // now, recreate poly // first, find outside contours and create new CPolyLines if necessary int n_ext_cont = 0; for( int ic=0; ic<m_gpc_poly->num_contours; ic++ ) { if( !(m_gpc_poly->hole)[ic] ) { if( n_ext_cont == 0 ) { // first external contour, replace this poly corner.RemoveAll(); side_style.RemoveAll(); m_ncorners = 0; for( int i=0; i<m_gpc_poly->contour[ic].num_vertices; i++ ) { int x = ((m_gpc_poly->contour)[ic].vertex)[i].x; int y = ((m_gpc_poly->contour)[ic].vertex)[i].y; if( i==0 ) Start( m_layer, m_w, m_sel_box, x, y, m_hatch, &m_id, m_ptr ); else AppendCorner( x, y, STRAIGHT, FALSE ); } Close(); n_ext_cont++; } else if( pa ) { // next external contour, create new poly CPolyLine * poly = new CPolyLine; pa->SetSize(n_ext_cont); // put in array (*pa)[n_ext_cont-1] = poly; for( int i=0; i<m_gpc_poly->contour[ic].num_vertices; i++ ) { int x = ((m_gpc_poly->contour)[ic].vertex)[i].x; int y = ((m_gpc_poly->contour)[ic].vertex)[i].y; if( i==0 ) poly->Start( m_layer, m_w, m_sel_box, x, y, m_hatch, &m_id, m_ptr ); else poly->AppendCorner( x, y, STRAIGHT, FALSE ); } poly->Close( STRAIGHT, FALSE ); n_ext_cont++; } } } // now add cutouts to the CPolyLine(s) for( int ic=0; ic<m_gpc_poly->num_contours; ic++ ) { if( (m_gpc_poly->hole)[ic] ) { CPolyLine * ext_poly = NULL; if( n_ext_cont == 1 ) { ext_poly = this; } else { // find the polygon that contains this hole for( int i=0; i<m_gpc_poly->contour[ic].num_vertices; i++ ) { int x = ((m_gpc_poly->contour)[ic].vertex)[i].x; int y = ((m_gpc_poly->contour)[ic].vertex)[i].y; if( TestPointInside( x, y ) ) ext_poly = this; else { for( int ext_ic=0; ext_ic<n_ext_cont-1; ext_ic++ ) { if( (*pa)[ext_ic]->TestPointInside( x, y ) ) { ext_poly = (*pa)[ext_ic]; break; } } } if( ext_poly ) break; } } if( !ext_poly ) ASSERT(0); for( int i=0; i<m_gpc_poly->contour[ic].num_vertices; i++ ) { int x = ((m_gpc_poly->contour)[ic].vertex)[i].x; int y = ((m_gpc_poly->contour)[ic].vertex)[i].y; ext_poly->AppendCorner( x, y, STRAIGHT, FALSE ); } ext_poly->Close( STRAIGHT, FALSE ); } } if( bRetainArcs ) RestoreArcs( &arc_array, pa ); FreeGpcPoly(); return n_ext_cont; }
// Restore arcs to a polygon where they were replaced with steps // If pa != NULL, also use polygons in pa array // int CPolyLine::RestoreArcs( CArray<CArc> * arc_array, CArray<CPolyLine*> * pa ) { // get poly info int n_polys = 1; if( pa ) n_polys += pa->GetSize(); CPolyLine * poly; // undraw polys and clear utility flag for all corners for( int ip=0; ip<n_polys; ip++ ) { if( ip == 0 ) poly = this; else poly = (*pa)[ip-1]; poly->Undraw(); for( int ic=0; ic<poly->GetNumCorners(); ic++ ) poly->SetUtility( ic, 0 ); // clear utility flag } // find arcs and replace them BOOL bFound; int arc_start; int arc_end; for( int iarc=0; iarc<arc_array->GetSize(); iarc++ ) { int arc_xi = (*arc_array)[iarc].xi; int arc_yi = (*arc_array)[iarc].yi; int arc_xf = (*arc_array)[iarc].xf; int arc_yf = (*arc_array)[iarc].yf; int n_steps = (*arc_array)[iarc].n_steps; int style = (*arc_array)[iarc].style; bFound = FALSE; // loop through polys for( int ip=0; ip<n_polys; ip++ ) { if( ip == 0 ) poly = this; else poly = (*pa)[ip-1]; for( int icont=0; icont<poly->GetNumContours(); icont++ ) { int ic_start = poly->GetContourStart(icont); int ic_end = poly->GetContourEnd(icont); if( (ic_end-ic_start) > n_steps ) { for( int ic=ic_start; ic<=ic_end; ic++ ) { int ic_next = ic+1; if( ic_next > ic_end ) ic_next = ic_start; int xi = poly->GetX(ic); int yi = poly->GetY(ic); if( xi == arc_xi && yi == arc_yi ) { // test for forward arc int ic2 = ic + n_steps; if( ic2 > ic_end ) ic2 = ic2 - ic_end + ic_start - 1; int xf = poly->GetX(ic2); int yf = poly->GetY(ic2); if( xf == arc_xf && yf == arc_yf ) { // arc from ic to ic2 bFound = TRUE; arc_start = ic; arc_end = ic2; } else { // try reverse arc ic2 = ic - n_steps; if( ic2 < ic_start ) ic2 = ic2 - ic_start + ic_end + 1; xf = poly->GetX(ic2); yf = poly->GetY(ic2); if( xf == arc_xf && yf == arc_yf ) { // arc from ic2 to ic bFound = TRUE; arc_start = ic2; arc_end = ic; style = 3 - style; } } if( bFound ) { poly->side_style[arc_start] = style; // mark corners for deletion from arc_start+1 to arc_end-1 for( int i=arc_start+1; i!=arc_end; ) { if( i > ic_end ) i = ic_start; poly->SetUtility( i, 1 ); if( i == ic_end ) i = ic_start; else i++; } break; } } if( bFound ) break; } } if( bFound ) break; } } if( bFound ) (*arc_array)[iarc].bFound = TRUE; } // now delete all marked corners for( int ip=0; ip<n_polys; ip++ ) { if( ip == 0 ) poly = this; else poly = (*pa)[ip-1]; for( int ic=poly->GetNumCorners()-1; ic>=0; ic-- ) { if( poly->GetUtility(ic) ) poly->DeleteCorner( ic, FALSE ); } } return 0; }
void POINT_EDITOR::addCorner( const VECTOR2I& aBreakPoint ) { EDA_ITEM* item = m_editPoints->GetParent(); const SELECTION& selection = m_selectionTool->GetSelection(); if( item->Type() == PCB_ZONE_AREA_T ) { getEditFrame<PCB_BASE_FRAME>()->OnModify(); getEditFrame<PCB_BASE_FRAME>()->SaveCopyInUndoList( selection.items, UR_CHANGED ); ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item ); CPolyLine* outline = zone->Outline(); // Handle the last segment, so other segments can be easily handled in a loop unsigned int nearestIdx = outline->GetCornersCount() - 1, nextNearestIdx = 0; SEG side( VECTOR2I( outline->GetPos( nearestIdx ) ), VECTOR2I( outline->GetPos( nextNearestIdx ) ) ); unsigned int nearestDist = side.Distance( aBreakPoint ); for( int i = 0; i < outline->GetCornersCount() - 1; ++i ) { side = SEG( VECTOR2I( outline->GetPos( i ) ), VECTOR2I( outline->GetPos( i + 1 ) ) ); unsigned int distance = side.Distance( aBreakPoint ); if( distance < nearestDist ) { nearestDist = distance; nearestIdx = i; nextNearestIdx = i + 1; } } // Find the point on the closest segment VECTOR2I sideOrigin( outline->GetPos( nearestIdx ) ); VECTOR2I sideEnd( outline->GetPos( nextNearestIdx ) ); SEG nearestSide( sideOrigin, sideEnd ); VECTOR2I nearestPoint = nearestSide.NearestPoint( aBreakPoint ); // Do not add points that have the same coordinates as ones that already belong to polygon // instead, add a point in the middle of the side if( nearestPoint == sideOrigin || nearestPoint == sideEnd ) nearestPoint = ( sideOrigin + sideEnd ) / 2; outline->InsertCorner( nearestIdx, nearestPoint.x, nearestPoint.y ); } else if( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) { bool moduleEdge = item->Type() == PCB_MODULE_EDGE_T; PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>(); frame->OnModify(); if( moduleEdge ) frame->SaveCopyInUndoList( getModel<BOARD>()->m_Modules, UR_MODEDIT ); else frame->SaveCopyInUndoList( selection.items, UR_CHANGED ); DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item ); if( segment->GetShape() == S_SEGMENT ) { SEG seg( segment->GetStart(), segment->GetEnd() ); VECTOR2I nearestPoint = seg.NearestPoint( aBreakPoint ); // Move the end of the line to the break point.. segment->SetEnd( wxPoint( nearestPoint.x, nearestPoint.y ) ); // and add another one starting from the break point DRAWSEGMENT* newSegment; if( moduleEdge ) { EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( segment ); assert( segment->GetParent()->Type() == PCB_MODULE_T ); newSegment = new EDGE_MODULE( *edge ); edge->SetLocalCoord(); } else { newSegment = new DRAWSEGMENT( *segment ); } newSegment->ClearSelected(); newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) ); newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) ); if( moduleEdge ) { static_cast<EDGE_MODULE*>( newSegment )->SetLocalCoord(); getModel<BOARD>()->m_Modules->Add( newSegment ); } else { getModel<BOARD>()->Add( newSegment ); } getView()->Add( newSegment ); } } }
void POINT_EDITOR::updateItem() const { EDA_ITEM* item = m_editPoints->GetParent(); switch( item->Type() ) { case PCB_LINE_T: case PCB_MODULE_EDGE_T: { DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item ); switch( segment->GetShape() ) { case S_SEGMENT: if( isModified( m_editPoints->Point( SEG_START ) ) ) segment->SetStart( wxPoint( m_editPoints->Point( SEG_START ).GetPosition().x, m_editPoints->Point( SEG_START ).GetPosition().y ) ); else if( isModified( m_editPoints->Point( SEG_END ) ) ) segment->SetEnd( wxPoint( m_editPoints->Point( SEG_END ).GetPosition().x, m_editPoints->Point( SEG_END ).GetPosition().y ) ); break; case S_ARC: { const VECTOR2I& center = m_editPoints->Point( ARC_CENTER ).GetPosition(); const VECTOR2I& start = m_editPoints->Point( ARC_START ).GetPosition(); const VECTOR2I& end = m_editPoints->Point( ARC_END ).GetPosition(); if( center != segment->GetCenter() ) { wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); segment->Move( moveVector ); m_editPoints->Point( ARC_START ).SetPosition( segment->GetArcStart() ); m_editPoints->Point( ARC_END ).SetPosition( segment->GetArcEnd() ); } else { segment->SetArcStart( wxPoint( start.x, start.y ) ); VECTOR2D startLine = start - center; VECTOR2I endLine = end - center; double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() ); // Adjust the new angle to (counter)clockwise setting bool clockwise = ( segment->GetAngle() > 0 ); if( clockwise && newAngle < 0.0 ) newAngle += 3600.0; else if( !clockwise && newAngle > 0.0 ) newAngle -= 3600.0; segment->SetAngle( newAngle ); } break; } case S_CIRCLE: { const VECTOR2I& center = m_editPoints->Point( CIRC_CENTER ).GetPosition(); const VECTOR2I& end = m_editPoints->Point( CIRC_END ).GetPosition(); if( isModified( m_editPoints->Point( CIRC_CENTER ) ) ) { wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter(); segment->Move( moveVector ); } else { segment->SetEnd( wxPoint( end.x, end.y ) ); } break; } default: // suppress warnings break; } // Update relative coordinates for module edges if( EDGE_MODULE* edge = dyn_cast<EDGE_MODULE*>( item ) ) edge->SetLocalCoord(); break; } case PCB_ZONE_AREA_T: { ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item ); zone->ClearFilledPolysList(); CPolyLine* outline = zone->Outline(); for( int i = 0; i < outline->GetCornersCount(); ++i ) { VECTOR2I point = m_editPoints->Point( i ).GetPosition(); outline->SetX( i, point.x ); outline->SetY( i, point.y ); } break; } case PCB_DIMENSION_T: { DIMENSION* dimension = static_cast<DIMENSION*>( item ); // Check which point is currently modified and updated dimension's points respectively if( isModified( m_editPoints->Point( DIM_CROSSBARO ) ) ) { VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetOrigin() ); VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() ); if( featureLine.Cross( crossBar ) > 0 ) dimension->SetHeight( -featureLine.EuclideanNorm() ); else dimension->SetHeight( featureLine.EuclideanNorm() ); } else if( isModified( m_editPoints->Point( DIM_CROSSBARF ) ) ) { VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetEnd() ); VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() ); if( featureLine.Cross( crossBar ) > 0 ) dimension->SetHeight( -featureLine.EuclideanNorm() ); else dimension->SetHeight( featureLine.EuclideanNorm() ); } else if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) ) { dimension->SetOrigin( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) ); m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ), m_editPoints->Point( DIM_FEATUREGO ) ) ); m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ), m_editPoints->Point( DIM_FEATUREDO ) ) ); } else if( isModified( m_editPoints->Point( DIM_FEATUREDO ) ) ) { dimension->SetEnd( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) ); m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ), m_editPoints->Point( DIM_FEATUREGO ) ) ); m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ), m_editPoints->Point( DIM_FEATUREDO ) ) ); } break; } default: break; } }
CPolyLine* CPolyLine::Fillet( unsigned int aRadius, unsigned int aSegments ) { CPolyLine* newPoly = new CPolyLine; if( !aRadius ) { newPoly->Copy( this ); return newPoly; } int polycount = GetContoursCount(); for( int contour = 0; contour < polycount; contour++ ) { unsigned int startIndex = GetContourStart( contour ); unsigned int endIndex = GetContourEnd( contour ); for( unsigned int index = startIndex; index <= endIndex; index++ ) { int x1, y1; // Current vertex long long xa, ya; // Previous vertex long long xb, yb; // Next vertex double nx, ny; x1 = m_CornersList[index].x; y1 = m_CornersList[index].y; if( index == startIndex ) { xa = m_CornersList[endIndex].x - x1; ya = m_CornersList[endIndex].y - y1; } else { xa = m_CornersList[index - 1].x - x1; ya = m_CornersList[index - 1].y - y1; } if( index == endIndex ) { xb = m_CornersList[startIndex].x - x1; yb = m_CornersList[startIndex].y - y1; } else { xb = m_CornersList[index + 1].x - x1; yb = m_CornersList[index + 1].y - y1; } double lena = hypot( xa, ya ); double lenb = hypot( xb, yb ); double cosine = ( xa * xb + ya * yb ) / ( lena * lenb ); double radius = aRadius; double denom = sqrt( 2.0 / ( 1 + cosine ) - 1 ); // Do nothing in case of parallel edges if( std::isinf( denom ) ) continue; // Limit rounding distance to one half of an edge if( 0.5 * lena * denom < radius ) radius = 0.5 * lena * denom; if( 0.5 * lenb * denom < radius ) radius = 0.5 * lenb * denom; // Calculate fillet arc absolute center point (xc, yx) double k = radius / sqrt( .5 * ( 1 - cosine ) ); double lenab = sqrt( ( xa / lena + xb / lenb ) * ( xa / lena + xb / lenb ) + ( ya / lena + yb / lenb ) * ( ya / lena + yb / lenb ) ); double xc = x1 + k * ( xa / lena + xb / lenb ) / lenab; double yc = y1 + k * ( ya / lena + yb / lenb ) / lenab; // Calculate arc start and end vectors k = radius / sqrt( 2 / ( 1 + cosine ) - 1 ); double xs = x1 + k * xa / lena - xc; double ys = y1 + k * ya / lena - yc; double xe = x1 + k * xb / lenb - xc; double ye = y1 + k * yb / lenb - yc; // Cosine of arc angle double argument = ( xs * xe + ys * ye ) / ( radius * radius ); if( argument < -1 ) // Just in case... argument = -1; else if( argument > 1 ) argument = 1; double arcAngle = acos( argument ); // Calculate the number of segments double tempSegments = (double) aSegments * ( arcAngle / ( 2 * M_PI ) ); if( tempSegments - (int) tempSegments > 0 ) tempSegments++; unsigned int segments = (unsigned int) tempSegments; double deltaAngle = arcAngle / segments; double startAngle = atan2( -ys, xs ); // Flip arc for inner corners if( xa * yb - ya * xb <= 0 ) deltaAngle *= -1; nx = xc + xs; ny = yc + ys; if( index == startIndex ) newPoly->Start( GetLayer(), KiROUND( nx ), KiROUND( ny ), GetHatchStyle() ); else newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) ); for( unsigned int j = 0; j < segments; j++ ) { nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius; ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius; newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) ); } } newPoly->CloseLastContour(); } return newPoly; }
CPolyLine* CPolyLine::Chamfer( unsigned int aDistance ) { CPolyLine* newPoly = new CPolyLine; if( !aDistance ) { newPoly->Copy( this ); return newPoly; } int polycount = GetContoursCount(); for( int contour = 0; contour < polycount; contour++ ) { unsigned int startIndex = GetContourStart( contour ); unsigned int endIndex = GetContourEnd( contour ); for( unsigned int index = startIndex; index <= endIndex; index++ ) { int x1, y1, nx, ny; long long xa, ya, xb, yb; x1 = m_CornersList[index].x; y1 = m_CornersList[index].y; if( index == startIndex ) { xa = m_CornersList[endIndex].x - x1; ya = m_CornersList[endIndex].y - y1; } else { xa = m_CornersList[index - 1].x - x1; ya = m_CornersList[index - 1].y - y1; } if( index == endIndex ) { xb = m_CornersList[startIndex].x - x1; yb = m_CornersList[startIndex].y - y1; } else { xb = m_CornersList[index + 1].x - x1; yb = m_CornersList[index + 1].y - y1; } unsigned int lena = KiROUND( hypot( xa, ya ) ); unsigned int lenb = KiROUND( hypot( xb, yb ) ); unsigned int distance = aDistance; // Chamfer one half of an edge at most if( 0.5 * lena < distance ) distance = int( 0.5 * lena ); if( 0.5 * lenb < distance ) distance = int( 0.5 * lenb ); nx = KiROUND( (distance * xa) / hypot( xa, ya ) ); ny = KiROUND( (distance * ya) / hypot( xa, ya ) ); if( index == startIndex ) newPoly->Start( GetLayer(), x1 + nx, y1 + ny, GetHatchStyle() ); else newPoly->AppendCorner( x1 + nx, y1 + ny ); nx = KiROUND( (distance * xb) / hypot( xb, yb ) ); ny = KiROUND( (distance * yb) / hypot( xb, yb ) ); newPoly->AppendCorner( x1 + nx, y1 + ny ); } newPoly->CloseLastContour(); } return newPoly; }
int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_Examine, bool aCreate_Markers ) { int nerrors = 0; // iterate through all areas for( int ia = 0; ia < GetAreaCount(); ia++ ) { ZONE_CONTAINER* Area_Ref = GetArea( ia ); CPolyLine* refSmoothedPoly = Area_Ref->GetSmoothedPoly(); if( !Area_Ref->IsOnCopperLayer() ) continue; // When testing only a single area, skip all others if( aArea_To_Examine && (aArea_To_Examine != Area_Ref) ) continue; for( int ia2 = 0; ia2 < GetAreaCount(); ia2++ ) { ZONE_CONTAINER* area_to_test = GetArea( ia2 ); CPolyLine* testSmoothedPoly = area_to_test->GetSmoothedPoly(); if( Area_Ref == area_to_test ) continue; // test for same layer if( Area_Ref->GetLayer() != area_to_test->GetLayer() ) continue; // Test for same net if( Area_Ref->GetNetCode() == area_to_test->GetNetCode() && Area_Ref->GetNetCode() >= 0 ) continue; // test for different priorities if( Area_Ref->GetPriority() != area_to_test->GetPriority() ) continue; // test for different types if( Area_Ref->GetIsKeepout() != area_to_test->GetIsKeepout() ) continue; // Examine a candidate zone: compare area_to_test to Area_Ref // Get clearance used in zone to zone test. The policy used to // obtain that value is now part of the zone object itself by way of // ZONE_CONTAINER::GetClearance(). int zone2zoneClearance = Area_Ref->GetClearance( area_to_test ); // Keepout areas have no clearance, so set zone2zoneClearance to 1 // ( zone2zoneClearance = 0 can create problems in test functions) if( Area_Ref->GetIsKeepout() ) zone2zoneClearance = 1; // test for some corners of Area_Ref inside area_to_test for( int ic = 0; ic < refSmoothedPoly->GetCornersCount(); ic++ ) { int x = refSmoothedPoly->GetX( ic ); int y = refSmoothedPoly->GetY( ic ); if( testSmoothedPoly->TestPointInside( x, y ) ) { // COPPERAREA_COPPERAREA error: copper area ref corner inside copper area if( aCreate_Markers ) { wxString msg1 = Area_Ref->GetSelectMenuText(); wxString msg2 = area_to_test->GetSelectMenuText(); MARKER_PCB* marker = new MARKER_PCB( COPPERAREA_INSIDE_COPPERAREA, wxPoint( x, y ), msg1, wxPoint( x, y ), msg2, wxPoint( x, y ) ); Add( marker ); } nerrors++; } } // test for some corners of area_to_test inside Area_Ref for( int ic2 = 0; ic2 < testSmoothedPoly->GetCornersCount(); ic2++ ) { int x = testSmoothedPoly->GetX( ic2 ); int y = testSmoothedPoly->GetY( ic2 ); if( refSmoothedPoly->TestPointInside( x, y ) ) { // COPPERAREA_COPPERAREA error: copper area corner inside copper area ref if( aCreate_Markers ) { wxString msg1 = area_to_test->GetSelectMenuText(); wxString msg2 = Area_Ref->GetSelectMenuText(); MARKER_PCB* marker = new MARKER_PCB( COPPERAREA_INSIDE_COPPERAREA, wxPoint( x, y ), msg1, wxPoint( x, y ), msg2, wxPoint( x, y ) ); Add( marker ); } nerrors++; } } // now test spacing between areas for( int icont = 0; icont < refSmoothedPoly->GetContoursCount(); icont++ ) { int ic_start = refSmoothedPoly->GetContourStart( icont ); int ic_end = refSmoothedPoly->GetContourEnd( icont ); for( int ic = ic_start; ic<=ic_end; ic++ ) { int ax1 = refSmoothedPoly->GetX( ic ); int ay1 = refSmoothedPoly->GetY( ic ); int ax2, ay2; if( ic == ic_end ) { ax2 = refSmoothedPoly->GetX( ic_start ); ay2 = refSmoothedPoly->GetY( ic_start ); } else { ax2 = refSmoothedPoly->GetX( ic + 1 ); ay2 = refSmoothedPoly->GetY( ic + 1 ); } for( int icont2 = 0; icont2 < testSmoothedPoly->GetContoursCount(); icont2++ ) { int ic_start2 = testSmoothedPoly->GetContourStart( icont2 ); int ic_end2 = testSmoothedPoly->GetContourEnd( icont2 ); for( int ic2 = ic_start2; ic2<=ic_end2; ic2++ ) { int bx1 = testSmoothedPoly->GetX( ic2 ); int by1 = testSmoothedPoly->GetY( ic2 ); int bx2, by2; if( ic2 == ic_end2 ) { bx2 = testSmoothedPoly->GetX( ic_start2 ); by2 = testSmoothedPoly->GetY( ic_start2 ); } else { bx2 = testSmoothedPoly->GetX( ic2 + 1 ); by2 = testSmoothedPoly->GetY( ic2 + 1 ); } int x, y; int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, 0, ax1, ay1, ax2, ay2, 0, zone2zoneClearance, &x, &y ); if( d < zone2zoneClearance ) { // COPPERAREA_COPPERAREA error : intersect or too close if( aCreate_Markers ) { wxString msg1 = Area_Ref->GetSelectMenuText(); wxString msg2 = area_to_test->GetSelectMenuText(); MARKER_PCB* marker = new MARKER_PCB( COPPERAREA_CLOSE_TO_COPPERAREA, wxPoint( x, y ), msg1, wxPoint( x, y ), msg2, wxPoint( x, y ) ); Add( marker ); } nerrors++; } } } } } } } return nerrors; }
/** * Function TestAreaPolygon * Test an area for self-intersection. * * @param CurrArea = copper area to test * @return : * -1 if arcs intersect other sides * 0 if no intersecting sides * 1 if intersecting sides, but no intersecting arcs * Also sets utility2 flag of area with return value */ int BOARD::TestAreaPolygon( ZONE_CONTAINER* CurrArea ) { CPolyLine* p = CurrArea->m_Poly; // first, check for sides intersecting other sides, especially arcs bool bInt = false; bool bArcInt = false; int n_cont = p->GetNumContours(); // make bounding rect for each contour std::vector<CRect> cr; cr.reserve( n_cont ); for( int icont = 0; icont<n_cont; icont++ ) cr.push_back( p->GetCornerBounds( icont ) ); for( int icont = 0; icont<n_cont; icont++ ) { int is_start = p->GetContourStart( icont ); int is_end = p->GetContourEnd( icont ); for( int is = is_start; is<=is_end; is++ ) { int is_prev = is - 1; if( is_prev < is_start ) is_prev = is_end; int is_next = is + 1; if( is_next > is_end ) is_next = is_start; int style = p->GetSideStyle( is ); int x1i = p->GetX( is ); int y1i = p->GetY( is ); int x1f = p->GetX( is_next ); int y1f = p->GetY( is_next ); // check for intersection with any other sides for( int icont2 = icont; icont2<n_cont; icont2++ ) { if( cr[icont].left > cr[icont2].right || cr[icont].bottom > cr[icont2].top || cr[icont2].left > cr[icont].right || cr[icont2].bottom > cr[icont].top ) { // rectangles don't overlap, do nothing } else { int is2_start = p->GetContourStart( icont2 ); int is2_end = p->GetContourEnd( icont2 ); for( int is2 = is2_start; is2<=is2_end; is2++ ) { int is2_prev = is2 - 1; if( is2_prev < is2_start ) is2_prev = is2_end; int is2_next = is2 + 1; if( is2_next > is2_end ) is2_next = is2_start; if( icont != icont2 || (is2 != is && is2 != is_prev && is2 != is_next && is != is2_prev && is != is2_next ) ) { int style2 = p->GetSideStyle( is2 ); int x2i = p->GetX( is2 ); int y2i = p->GetY( is2 ); int x2f = p->GetX( is2_next ); int y2f = p->GetY( is2_next ); int ret = FindSegmentIntersections( x1i, y1i, x1f, y1f, style, x2i, y2i, x2f, y2f, style2 ); if( ret ) { // intersection between non-adjacent sides bInt = true; if( style != CPolyLine::STRAIGHT || style2 != CPolyLine::STRAIGHT ) { bArcInt = true; break; } } } } } if( bArcInt ) break; } if( bArcInt ) break; } if( bArcInt ) break; } if( bArcInt ) CurrArea->utility2 = -1; else if( bInt ) CurrArea->utility2 = 1; else CurrArea->utility2 = 0; return CurrArea->utility2; }