コード例 #1
0
ファイル: Pen.cpp プロジェクト: dparks1134/Art
void Line::setLine(const Point& start, float angle, uint width, uint height)
{
	m_start = start;
	m_angle = angle;

	// find where line intersects edge of canvas
	while(angle < 0) angle += 360;
	angle = int(angle + 0.5) % 360;

	Line lineVec(m_start, m_start.offset(angle));

	Point intersection;
	if(angle >= 0 && angle < 90)
	{
		intersection = Geometry::verticalIntersect(lineVec, width-1);
		Point test = Geometry::horizontalIntersect(lineVec, height-1);
		if(test.x() < intersection.x())
			intersection = test;
	}
	else if(angle >= 90 && angle < 180)
	{
		intersection = Geometry::verticalIntersect(lineVec, 0);
		Point test = Geometry::horizontalIntersect(lineVec, height-1);
		if(test.x() > intersection.x() || intersection.x() == std::numeric_limits<float>::max())
			intersection = test;
	}
	else if(angle >= 180 && angle < 270)
	{
		intersection = Geometry::verticalIntersect(lineVec, 0);
		Point test = Geometry::horizontalIntersect(lineVec, 0);
		if(test.x() > intersection.x() && test.x() != std::numeric_limits<float>::max())
			intersection = test;
	}
	else if(angle >= 270 && angle < 360)
	{
		intersection = Geometry::verticalIntersect(lineVec, width-1);
		Point test = Geometry::horizontalIntersect(lineVec, 0);
		if(test.x() < intersection.x())
			intersection = test;
	}

	m_start = start;
	m_end = intersection;
}
コード例 #2
0
void AcDbDoubleClickEditPline::startEdit(AcDbEntity *pEnt, AcGePoint3d clickpt)
{
	// Implement the startEdit notification handler to catch when
	// a user double-clicks a 'POLYLINE' entity
	
	// Get the Current Document
	AcApDocument *pDoc=acDocManager->curDocument(); 
	AcDbPolyline *pLine;
		
	// Cast the AcDbEntity pointer to AcDbPolyline
	if(pEnt->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue)
		pLine=AcDbPolyline::cast(pEnt);
	else
	{
		acutPrintf("Error: Invalid AcDbPolyline Object");
		return;
	}
	
	acDocManager->lockDocument(pDoc,AcAp::kWrite);
	
	// Upgrade to write
	if(pLine->upgradeOpen()!=Acad::eOk)
	{
		acutPrintf("Error: Could Not open AcDbPolyline Object");
		return;
	}
	
	// iterate through all the vertices to find which
	// segment was clicked on, and place a vertex there.
	for(unsigned int c=0;c<pLine->numVerts()-1;c++)
	{
		AcGePoint3d pt1,pt2;
		pLine->getPointAt(c,pt1);
		pLine->getPointAt(c+1,pt2);
		AcGeVector3d lineVec(pt2-pt1),clickVec(clickpt-pt1),
			clickVec2(pt2-clickpt);
		double ang=lineVec.angleTo(clickVec);
		
		// This is the filter...
		// .05 (5% of lineVec length) is an arbitrary length...
		if((sin(ang)*clickVec.length()<.05*lineVec.length()) && 
			clickVec.length()<lineVec.length() && 
			clickVec2.length()<lineVec.length()) 
		{
			// Add the point Here!
			ads_point outPt;
			acdbWcs2Ecs(asDblArray(clickpt),outPt,asDblArray(pLine->normal()),Adesk::kFalse);	
			pLine->addVertexAt(c+1,asPnt2d(outPt));
			break;
		}
	}
	
	pLine->close();

	acDocManager->unlockDocument(pDoc);
	
	// invoking acedSSSetFirst(NULL,NULL) here will clear the
	// pickfirst selection, if desired (not With pline though).
	//acedSSSetFirst(NULL,NULL);
	
	// Update the graphics...
	pLine->draw();
	actrTransactionManager->flushGraphics();
	acedUpdateDisplay();
}