Jig and user input

Jig and user input

Anonymous
Not applicable
1,851 Views
3 Replies
Message 1 of 4

Jig and user input

Anonymous
Not applicable

Hi, I have created jig for my entities.

For the simplicity, imagine that user draws a line (end point of line)

 

While jigging, the user has some possibilities:

1. Just click with a mouse to get a point

2. Enter keyword (for example: "show_line_props")

3. Enter distance and angle (for example: "@100<45")

4. Enter distance (for example: "100")

 

So now:

Ad. 1. This is the simplest case and it works all the time 😉

Ad. 2. I had to do some things here to get it to work:

AcEdJig::DragStatus PreviewJig::sampler()
{	
	if(m_keywords.length())
		setKeywordList(m_keywords.kACharPtr());

	//...

	AcEdJig::DragStatus status = acquirePoint(m_currentPoint);
	return status;
}

And that works as well.

Ad. 3. I had to distinguish user input type. I did it with InputPointMonitor and it works.

Ad. 4. This is the hardest one, I cannot solve.

 

So, I added some options in sampler:

m_flags = (UserInputControls)(AcEdJig::kAcceptOtherInputString | AcEdJig::kDisableDirectDistanceInput);
setUserInputControls(m_flags);

These flags make acquirePoint to return kOther. So now I know, that user didn't click, didn't enter a keyword, so he must have entered a distance. But the question is - how can I read the distance? acedGetInput always gives me an empty string.

0 Likes
Accepted solutions (1)
1,852 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

OK, I found solution in the documentation. Call to acquireString is needed after acquirePoint.

0 Likes
Message 3 of 4

Matti72
Advocate
Advocate

I don't have a simple solution for your problem (and I'm not sure if there is one...)

 

But there are two possibilities to get it working (as I think you want to have it).

 

The easiest way would be to let the user change what he want to do by keyword (enter point or distance... select distance) and then you can call an aquireDistance instead of the aquirePoint. 

 

The other solution (which would cover your points 3 and 4 is to add a dimension to your jig. Than it would look like the jig if you draw a line in AutoCAD (you can specify a point or a distance and a angle).

 

But this is a little bit more complicated...

 

Look for 

 

void updateDimension();
virtual AcDbDimDataPtrArray* dimData(const double dimScale);
bool addDimData();
virtual Acad::ErrorStatus setDimValue(const AcDbDimData *pdimData, const double dimValue);

 

to add a AcDbAlignedDimension to your Jig

 

 

Just to get you started here are a small sample of how this functions can look:

AcDbDimDataPtrArray* TestJig::dimData(const double dimScale)
{
	return m_pDimDataArray;
}

bool TestJig::addDimData()
{
	if (m_myRectangle == NULL)
		return false;

	if (m_pDimDataArray == NULL) 
	{
		m_pDimDataArray = new AcDbDimDataPtrArray();
	} 
	else 
	{
		for (int i = 0; i < m_pDimDataArray->length(); i++)
		{
			AcDbDimData *pData = (*m_pDimDataArray)[i];
			delete pData;
		}
		m_pDimDataArray->setLogicalLength(0);
	}


	if (m_nStep == 0)
		return true;

	AcGeVector3d vecNormal;
	vecNormal = GetViewNormal();

	AcDbAlignedDimension *pAlnDim1 = new AcDbAlignedDimension();
	pAlnDim1->setDatabaseDefaults();
	pAlnDim1->setXLine1Point(m_Start);
	AcGePoint3d pntWidth = m_Start + (m_myRectangle->m_vecWidth * m_myRectangle->m_dblWidth);
	pAlnDim1->setXLine2Point(pntWidth);
	pAlnDim1->setNormal(vecNormal);
	AcDbDimData *dimData1 = new AcDbDimData(pAlnDim1);
	int * DimIndex;
	LP_MALLOC( DimIndex, 1 );
	*DimIndex = 1;
	dimData1->setAppData(DimIndex);
	dimData1->setDimEditable(true);
	m_pDimDataArray->append(dimData1);	
	//if (m_nStep > 1)
	{
		AcDbAlignedDimension *pAlnDim2 = new AcDbAlignedDimension();
		pAlnDim2->setDatabaseDefaults();
		pAlnDim2->setXLine1Point(m_Start);
		AcGePoint3d pntHeight = m_Start + (m_myRectangle->m_vecHeight * m_myRectangle->m_dblHeight);
		pAlnDim2->setXLine2Point(pntHeight);
		pAlnDim2->setNormal(vecNormal);
		AcDbDimData *dimData2 = new AcDbDimData(pAlnDim2);
		int * DimIndex;
		LP_MALLOC( DimIndex, 1 );
		*DimIndex = 2;
		dimData2->setAppData(DimIndex);
		dimData2->setDimEditable(true);
		m_pDimDataArray->append(dimData2);	
	}

	return true;
}

void TestJig::updateDimension()
{
	if (!m_myRectangle || !m_pDimDataArray || (m_pDimDataArray->length() <= 0))
		return;

	for (int i = 0; i < m_pDimDataArray->length(); i++)
	{
		AcDbDimData *pData = (*m_pDimDataArray)[i];
		int iAppData = *( static_cast<int *>(pData->appData()) );
		if (iAppData == 1)
		{
			AcDbDimension *pDim = (AcDbDimension*)pData->dimension();
			AcDbAlignedDimension *pAlnDim = AcDbAlignedDimension::cast(pDim);
			if (pAlnDim == NULL)
				continue;
			AcGePoint3d pntWidth = m_Start + (m_myRectangle->m_vecWidth * m_myRectangle->m_dblWidth);
			pAlnDim->setXLine1Point(m_Start);
			pAlnDim->setXLine2Point(pntWidth);
			pAlnDim->setDimLinePoint(pntWidth);
			pAlnDim->setNormal(GetViewNormal());
		}
		if (iAppData == 2)
		{
			AcDbDimension *pDim = (AcDbDimension*)pData->dimension();
			AcDbAlignedDimension *pAlnDim = AcDbAlignedDimension::cast(pDim);
			if (pAlnDim == NULL)
				continue;
			AcGePoint3d pntHeight = m_Start + (m_myRectangle->m_vecHeight * m_myRectangle->m_dblHeight);
			pAlnDim->setXLine1Point(m_Start);
			pAlnDim->setXLine2Point(pntHeight);
			pAlnDim->setDimLinePoint(pntHeight);
			pAlnDim->setNormal(GetViewNormal());
		}
	}
	return;
}

Acad::ErrorStatus TestJig::setDimValue(const AcDbDimData *pdimData, const double dimValue)
{
	int iAppData = *( static_cast<int *>(pdimData->appData()) );
	if (iAppData == 1)
	{
		m_myRectangle->m_dblWidth = dimValue;
		if (m_bSquare)
			m_myRectangle->m_dblHeight = dimValue;
		m_nStep++;
	}
	if (iAppData == 2)
	{
		m_myRectangle->m_dblHeight = dimValue;
		if (m_nStep == 2)
			m_nStep++;
		else
		{
			m_bHeightSetByDimension = TRUE;
		}
	}
	return Acad::eOk;
}
0 Likes
Message 4 of 4

st0426
Advocate
Advocate

GOOD

0 Likes