update cursorPoint after setDimValue Jig

update cursorPoint after setDimValue Jig

Anonymous
Not applicable
818 Views
0 Replies
Message 1 of 1

update cursorPoint after setDimValue Jig

Anonymous
Not applicable

Hi,

 

I'm using AcEdJig.

 

I need to use 4 DIFFERENT acdbdimdata in order to set position of block from external box.

The problem is that I change properly Block position/static annotation/second dimdata but I can't change cursorPoint. 

So when  I re-use acquire point, the position of mouse is not update.

How to update cursorPoint?

 

Attached you will find source and video.

 

Regards,

 

Mario

 
#include "StdAfx.h"
#include "JigMensola.h"
#include "SctBlocchi.h"
#include "SctQuotatura.h"
#include "SctDynBlock.h"

//#include "sctLib\SctUtility.h"
//#include "sctLib\SctBlocchi.h"
//#include "Campata.h"
//#include "Configurazione.h"

extern CString BLOCCHI;
extern bool JIGCQE;
extern AcGeVector3d vettore;
extern bool UPDATEPOINTCQE;


JigMensola::JigMensola(void)
{
	
	
}


//JigMensola::JigMensola(AcDbVoidPtrArray m_polylines,AcGePoint3d pInse,vector<PuntoDiSospensione> pds,int modIns)
//{
//	intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
//	//this->m_ids_lines=m_ids_lines;
//	this->pInse=pInse;
//	this->m_polylines=m_polylines;
//	this->pds=pds;
//	this->modIns=modIns;
//}	
//

JigMensola::~JigMensola(void)
{
	intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
}

BOOL WinCallBack1(MSG *pMsg)
{
      if(pMsg->message== WM_KEYDOWN)
      {
            if((pMsg->wParam)== VK_CONTROL)//ENTER Pressed

            {
			/*	static AcGePoint3d pointTmp1;
				AcEdJig::DragStatus stato = AcEdJig::kNormal;
				stat = acquirePoint(pointTmp1);
			acutPrintf(L"\nCONTROL  %.0f;%.0f;%.0f",pointTmp1.x,pointTmp1.y,pointTmp1.z);*/
				//AcGePoint3d point;
				//Acad::ErrorStatus es;
				//AcDbBlockTableRecord *pBlockTableRecord;
				//
				////se non c'è alcuno SNAP Point esce
				//if (0==snapPoints.length())
				//	return FALSE;

				////resetta sul primo snapPoint
				//if (pc>=snapPoints.length())
				//	pc=0;
				//
				////verifica che l'id sia valido
				//if (id.isValid() && !id.isErased() && !id.isNull())
				//{
				//	es= acdbOpenObject (pBlockTableRecord, id, AcDb::kForWrite);
				//	if (Acad::eOk==es)
				//	{
				//		acutPrintf(L"\n origin [%d]: %.3f,%.3f,%.3f",pc,snapPoints.at(pc).x,snapPoints.at(pc).y,snapPoints.at(pc).z);
				//		pBlockTableRecord->setOrigin(snapPoints.at(pc));
				//		pc=pc+1;
				//		
				//		pBlockTableRecord->close();
				//	}
				//}
				//
				return TRUE; //Block message for AutoCAD
            }
            return FALSE;

      }
      return FALSE;
}



bool JigMensola::doIt(CString nomeBlocco,AcDbObjectId idColonna, CString layer,AcGePoint3d *pInse)
{
	
	
	Acad::ErrorStatus es;
	AcDbObjectId idBlock,id,id_quota1,id_quota2,id_quota3,id_quota4;
	AcGePoint3d pMinCol,pMaxCol,PinseCol;
	//sctUtility::getExtents(idColonna,&pMinCol,&pMaxCol);
	double rot=0;
	sctUtility::getBlockInfo(idColonna,&rot,&PinseCol);
		SctDynBlock dyn;
		
		pMinCol=PinseCol;
		pMinCol.z=0.0;
		pMaxCol.x=PinseCol.x+dyn.getPropValueDouble(idColonna,L"L");
		pMaxCol.y=PinseCol.y+dyn.getPropValueDouble(idColonna,L"H");
		pMaxCol.z=0.0;

	SctBlocchi b;
	if (!b.addBlockToDatabase(nomeBlocco,&idBlock))
		return false;

	m_block= new AcDbBlockReference(AcGePoint3d(0,0,0),idBlock);

	int p=0;
	id=idBlock;
	AcGeMatrix3d mat;
	mat.setToIdentity();

	//Set dell'allineamento iniziale del blocco che viene inserito
	//Il blocco deve essere disegnato con la parte passante rivolta sulla Y

	/*quota1=true;
	quota2=true;
	quota3=true;
	quota4=true;*/
	quota=0;
	AcGePoint3dArray puntiGrip;
	AcDbEntity* obj;
    AcDbIntArray geomIds;
  /* AcDbEntity m_quota;*/
    AcGePoint3d tmpPt;
	AcGePoint3d pIns;
	AcGePoint3d arr,part,mid;
	arr[0]=pMinCol.x;
	arr[1]=0;
	arr[2]=0;
	part[0]=pMaxCol.x;
	part[1]=0;
	part[2]=0;
	partenza=part;
	entityList.append(m_block);
	sctUtility::mid_point(&mid,part,arr);
	EntQ1= new AcDbAlignedDimension(part,arr,mid);
	entityList.append(EntQ1);

	///SctQuotatura *sq=new SctQuotatura();
	//sq->QuotaDuePunti(part,arr,0,0,L"STEEL",&id_quota1,L"QUOTE_PROVA",15,15,L"");
	part[0]=pMaxCol.x;
	part[1]=pMaxCol.y;
	part[2]=0;
	partenza1=part;
	sctUtility::mid_point(&mid,part,arr);
	EntQ2= new AcDbAlignedDimension(part,arr,mid);
	entityList.append(EntQ2);
	////sq->QuotaDuePunti(part,arr,0,0,L"STEEL",&id_quota2,L"QUOTE_PROVA",15,15,L"");
	part[0]=pMinCol.x;
	part[1]=0;
	part[2]=0;
	partenza2=part;
	////sq->QuotaDuePunti(part,arr,0,0,L"STEEL",&id_quota3,L"QUOTE_PROVA",15,15,L"");
	////sq->QuotaDuePunti(part,arr,0,0,L"STEEL",&id_quota4,L"QUOTE_PROVA",15,15,L"");*/
	sctUtility::mid_point(&mid,part,arr);
	EntQ3= new AcDbAlignedDimension(part,arr,mid);
	entityList.append(EntQ3);
	EntQ4= new AcDbAlignedDimension(part,arr,mid);
	entityList.append(EntQ4);
	m_entityList.setEntityList (entityList);
	

	

	

	//per appendere tutte le entità
	//append();
	AcEdJig::setDispPrompt(L"\nInserisci ....");
	/*acedRegisterFilterWinMsg(WinCallBack1);
	AcEdJig::DragStatus stat = AcEdJig::drag();
	acedRemoveFilterWinMsg(WinCallBack1);
	quota++;*/
	AcEdJig::DragStatus stat = AcEdJig::kNormal;
	bool primoGiro=true;
	JIGCQE = false;
	UPDATEPOINTCQE=false;
	while(stat!=AcEdJig::kCancel||primoGiro)
	{
		 
		 stat = AcEdJig::drag();
		 
		 
		 primoGiro=false;
		 quota++;
		 //acutPrintf(L"\nSTAT %d quota %d", stat, quota);
		 m_dimData.removeAll();
		 

		 acutPrintf(L"\nSTAT %d quota %d", stat, quota);
		 //m_cursorPoint=pEnd;
		 /*Nsettata=-1;*/
	}
	JIGCQE = false;
	UPDATEPOINTCQE = false;
	AcDbEntity *Ent=NULL;
		
	//E' necessario aggiungere i dati estesi con le linee di taglio
	//altrimenti i tubi non vengono tagliati
	/*AcDbEntity *pEnt=NULL;
	if (acdbOpenObject(pEnt,m_block1->id(),AcDb::kForWrite)==Acad::eOk) 
	{
			pEnt->setLayer(layer);
			pEnt->close();
			pEnt=NULL;
	}*/

	//SctUtility::AccendiUnLayer(layer,0);

	pInse->x=m_cursorPoint.x;
	pInse->y=m_cursorPoint.y;

	return false;
}


AcEdJig::DragStatus JigMensola::sampler()
{
	DragStatus stat=AcEdJig::kNormal;
	
    {
		//inserimento blocco e richiesta punto
		AcEdJig::setUserInputControls(
			(UserInputControls)(AcEdJig::kAccept3dCoordinates | AcEdJig::kNoNegativeResponseAccepted | AcEdJig::kNoZeroResponseAccepted));
		
		static AcGePoint3d pointTmp;

		/*if (UPDATEPOINTCQE)
		{
			
			return AcEdJig::kNoChange;
		}*/
		/*if(SETDIM)
		{
			SETDIM=false;
			return AcEdJig::kNoChange;
		}
		else*/
			stat = acquirePoint(pointTmp);
		
		//acutPrintf(L"\npointTmp %.0f;%.0f;%.0f\n",pointTmp.x,pointTmp.y,pointTmp.z);
		if(pointTmp != m_cursorPoint/*&& settataQuota!=true*/)
		{
			acutPrintf(L"\npointTmp %.0f;%.0f;%.0f m_cursorPoint %.0f;%.0f;%.0f",pointTmp.x,pointTmp.y,pointTmp.z,m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z);
			m_cursorPoint = pointTmp;	
			
		}
		else if (stat == AcEdJig::kNormal)
		{
			/*m_cursorPoint.set(m_NEWcursorPoint.x,m_NEWcursorPoint.y,m_NEWcursorPoint.z);
			settataQuota = false;*/
			//acutPrintf(L"\nelse %.0f;%.0f;%.0f\n",m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z);
				return AcEdJig::kNoChange;
		}
	 }

	return stat;
}


Adesk::Boolean JigMensola::update()
{
	
	AcDbBlockReference* pRef=NULL;
	AcDbPolyline *pLine=NULL;
	AcDbLine* pQ=NULL;
	AcDbAlignedDimension* pQuo=NULL;
	AcDbEntity *xEntH=NULL;
	Acad::ErrorStatus es;
	AcGeVector3d dir1;
	AcGeVector3d dir2;
	acutPrintf(L"\nupdate");
	double distanzaCond=0.6;
	/*distanzaCond=Configurazione::getInstance().getDistanzaConduttori()*0.5;
	*/
	//inserimento dell'elemento
	intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
	pEnd=AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z);
	
	intersectionPoints.removeAll();
	AcDbPolyline *tracciatura=NULL;
	AcGePoint3d start;
	AcGePoint3d midP;

	//JIGCQE = true;
	for(int j=0;j<m_entityList.m_entities.length()/*-1*/;j++)
	{
		xEntH=static_cast<AcDbEntity*>(m_entityList.m_entities.at(j));
		

		//l'entità che si sta aggiornando è la linea di tracciatura mensola
		if(xEntH->isKindOf(AcDbBlockReference::desc()) && j==0)
		{
			
					
		//L'utente sta inserendo il blocco che si deve allineare automaticamente
		//al tubo o ai tubi ammesso che esista
		pRef=static_cast<AcDbBlockReference*>(m_block);
		if (settataQuota)
		{
			pEnd=dimEndNew;
			
			settataQuota = false;
		}

		
		//JIGCQE = true;
		
		es=pRef->setPosition(pEnd);
		//m_cursorPoint = pEnd;
		//JIGCQE = true;
		//JIGCQE = true;
		//acutPrintf(L"\nUPDATE pEnd %.0f;%.0f;%.0f\n",pEnd.x,pEnd.y,pEnd.z);
		es=pRef->setScaleFactors(AcGeScale3d(1,1,1));
		//allineaAssi(pRef);
		}

		//if(xEntH->isKindOf(AcDbLine::desc()) && j==1)
		//{
		//	pQ=AcDbLine::cast(xEntH);
		//	pQ->setEndPoint(pEnd);
		//	
		//}


		
		//if(xEntH->isKindOf(AcDbAlignedDimension::desc()) && j==1)
		//{
		////quota 1	
		//	
		//	AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(m_dimData.at(0)) ;
		//	int inputNumber =-1 ;
		//	//- Find the dim data being passed so we can determine the input number
		//	if ( m_dimData.find (dimDataNC, inputNumber) ) 
		//	{
		//		//- Now get the dimension
		//		AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
		//		//- Check it's the type of dimension we want
		//		AcDbAlignedDimension *p =AcDbAlignedDimension::cast (pDim) ;

		//		//- If ok
		//		if(p)
		//		{
		//			AcGePoint3d mid;
		//			start=p->xLine1Point();
		//			start.y=pEnd.y;
		//			sctUtility::mid_point(&mid,start,pEnd);
		//			/*mid.x=(ref1.x+m_cursorPoint.x)/2.0;
		//			mid.y=(ref1.y+m_cursorPoint.y)/2.0;
		//			mid.z=m_cursorPoint.z;*/

		//			p->setXLine1Point(start);
		//			p->setXLine2Point(AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z));
		//			p->setDimLinePoint(mid);
		//			p->setDynamicDimension(true);
		//		}
		//	}
		//	
		//}
		//	//pQuo=AcDbAlignedDimension::cast(xEntH);
		//	//start=pQuo->xLine1Point();
		//	//start.y=pEnd.y;
		//	//sctUtility::mid_point(&midP,start,pEnd);
		//	//
		//	//es=pQuo->setXLine1Point(start);
		//	//es=pQuo->setXLine2Point(pEnd);
		//	//pQuo->setDimLinePoint(midP);
		//	//
		//	///*Ptest.x=pEnd.x+fabs(start.x-pEnd.x)/2;
		//	//Ptest.y=pEnd.y;
		//	//Ptest.z=0;
		//	//es=pQuo->setTextPosition(Ptest);*/
		//
		//
		//}

		if(xEntH->isKindOf(AcDbAlignedDimension::desc()) && j==1)
		{
		//quota 2
			pQuo=AcDbAlignedDimension::cast(xEntH);
			start=pQuo->xLine1Point();
			start.y=pEnd.y;
			
			sctUtility::mid_point(&midP,start,pEnd);
			
			es=pQuo->setXLine1Point(start);
			es=pQuo->setXLine2Point(pEnd);
			pQuo->setDimLinePoint(midP);
			/*Ptest.y=pEnd.y+fabs(start.y-pEnd.y)/2;
			Ptest.x=pEnd.x;
			Ptest.z=0;
			es=pQuo->setTextPosition(Ptest);*/
		
		
		}
		if(xEntH->isKindOf(AcDbAlignedDimension::desc()) && j==2)
		{
		//quota 2
			pQuo=AcDbAlignedDimension::cast(xEntH);
			start=pQuo->xLine1Point();
			start.x=pEnd.x;
			
			sctUtility::mid_point(&midP,start,pEnd);
			
			es=pQuo->setXLine1Point(start);
			es=pQuo->setXLine2Point(pEnd);
			pQuo->setDimLinePoint(midP);
			/*Ptest.y=pEnd.y+fabs(start.y-pEnd.y)/2;
			Ptest.x=pEnd.x;
			Ptest.z=0;
			es=pQuo->setTextPosition(Ptest);*/
		
		
		}
		if(xEntH->isKindOf(AcDbAlignedDimension::desc()) && j==3)
		{
		//quota 3	
			pQuo=AcDbAlignedDimension::cast(xEntH);
			start=pQuo->xLine1Point();
			start.y=pEnd.y;
			
			sctUtility::mid_point(&midP,start,pEnd);
			
			es=pQuo->setXLine1Point(start);
			es=pQuo->setXLine2Point(pEnd);
			pQuo->setDimLinePoint(midP);
		/*	Ptest.x=pEnd.x+fabs(start.x-pEnd.x)/2;
			Ptest.y=pEnd.y;
			Ptest.z=0;
			es=pQuo->setTextPosition(Ptest);*/

		
		
		}
		if(xEntH->isKindOf(AcDbAlignedDimension::desc()) && j==4)
		{
		//quota 4
			pQuo=AcDbAlignedDimension::cast(xEntH);
			start=pQuo->xLine1Point();
			start.x=pEnd.x;
			
			sctUtility::mid_point(&midP,start,pEnd);
			
			es=pQuo->setXLine1Point(start);
			es=pQuo->setXLine2Point(pEnd);
			pQuo->setDimLinePoint(midP);
			/*Ptest.y=pEnd.y+fabs(start.y-pEnd.y)/2;
			Ptest.x=pEnd.x;
			Ptest.z=0;
			es=pQuo->setTextPosition(Ptest);*/

		
		
		}

	//al tubo o ai tubi ammesso che esista
		/*pRef=static_cast<AcDbBlockReference*>();
		es=pRef->setPosition(pEnd);
		es=pRef->setScaleFactors(AcGeScale3d(1,1,1));*/
	}

	int valoreQuota=quota%4;
	if (valoreQuota==0 /*|| Nsettata==0*/)
	{
			AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(m_dimData.at(0)) ;
			int inputNumber =-1 ;
			//- Find the dim data being passed so we can determine the input number
			if ( m_dimData.find (dimDataNC, inputNumber) ) 
			{
				//- Now get the dimension
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *p =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if (p) {
					AcGePoint3d mid;

					start=partenza;
					start.y=pEnd.y;
					sctUtility::mid_point(&mid,start,pEnd);
					/*mid.x=(ref1.x+m_cursorPoint.x)/2.0;
					mid.y=(ref1.y+m_cursorPoint.y)/2.0;
					mid.z=m_cursorPoint.z;*/

					p->setXLine1Point(start);
					p->setXLine2Point(AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z));
					p->setDimLinePoint(mid);
					p->setDynamicDimension(true);
					//d->setDimension(p);
				}
			}
		}
	
	if (valoreQuota==1|| Nsettata==1)
		{
			AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(m_dimData.at(0)) ;
			int inputNumber =-1 ;
			//- Find the dim data being passed so we can determine the input number
			if ( m_dimData.find (dimDataNC, inputNumber) ) 
			{
				//- Now get the dimension
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *p =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if (p) {
					AcGePoint3d mid;

					start=partenza1;

					start.x=pEnd.x;
					sctUtility::mid_point(&mid,start,pEnd);
					/*mid.x=(ref1.x+m_cursorPoint.x)/2.0;
					mid.y=(ref1.y+m_cursorPoint.y)/2.0;
					mid.z=m_cursorPoint.z;*/

					p->setXLine1Point(start);
					p->setXLine2Point(AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z));
					p->setDimLinePoint(mid);
					p->setDynamicDimension(true);
					//d->setDimension(p);
				}
			}
		}
	if (valoreQuota==2|| Nsettata==2)
		{
			AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(m_dimData.at(0)) ;
			int inputNumber =-1 ;
			//- Find the dim data being passed so we can determine the input number
			if ( m_dimData.find (dimDataNC, inputNumber) ) 
			{
				//- Now get the dimension
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *p =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if (p) {
					AcGePoint3d mid;

					start=partenza2;

					start.y=pEnd.y;
					sctUtility::mid_point(&mid,start,pEnd);
					/*mid.x=(ref1.x+m_cursorPoint.x)/2.0;
					mid.y=(ref1.y+m_cursorPoint.y)/2.0;
					mid.z=m_cursorPoint.z;*/

					p->setXLine1Point(start);
					p->setXLine2Point(AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z));
					p->setDimLinePoint(mid);
					p->setDynamicDimension(true);
					//d->setDimension(p);
				}
			}
		}
	if (valoreQuota==3|| Nsettata==3)
		{
			AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(m_dimData.at(0)) ;
			int inputNumber =-1 ;
			//- Find the dim data being passed so we can determine the input number
			if ( m_dimData.find (dimDataNC, inputNumber) ) 
			{
				//- Now get the dimension
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *p =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if (p) {
					AcGePoint3d mid;

					start=partenza2;

					start.x=pEnd.x;
					sctUtility::mid_point(&mid,start,pEnd);
					/*mid.x=(ref1.x+m_cursorPoint.x)/2.0;
					mid.y=(ref1.y+m_cursorPoint.y)/2.0;
					mid.z=m_cursorPoint.z;*/

					p->setXLine1Point(start);
					p->setXLine2Point(AcGePoint3d(m_cursorPoint.x,m_cursorPoint.y,m_cursorPoint.z));
					p->setDimLinePoint(mid);
					p->setDynamicDimension(true);
					//d->setDimension(p);
				}
			}
		}
	/*if(settataQuota)*/
	Nsettata=-1;
	return Adesk::kTrue;
}


//PuntoDiSospensione JigMensola::cercaPds(AcGePoint3d p,AcDbPolyline *tracciatura)
//{
//	double distanza=1000000000;
//	AcGePoint3d punto,pTrovato;
//	PuntoDiSospensione pd;
//	int indice=0;
//	double distanzaPdsLineaTeoricaTracciatura=0.0;
//	AcDbLine *teorica=new AcDbLine();
//	AcGePoint3dArray intersectionPoints;
//	intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
//	for (int i=0;i<pds.size();i++)
//	{
//		intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
//		teorica->setStartPoint(pds.at(i).getPinse());
//		teorica->setEndPoint(p);
//		teorica->intersectWith (tracciatura, AcDb::kOnBothOperands, intersectionPoints);
//
//		tracciatura->getClosestPointTo(pds.at(i).getPinse(),pTrovato);
//		distanzaPdsLineaTeoricaTracciatura=pTrovato.distanceTo(pds.at(i).getPinse());
//		acutPrintf(L"\n%.2f",distanzaPdsLineaTeoricaTracciatura);
//		//la nuova campata NON deve intesercare la linea di tracciatura teorica
//		if (intersectionPoints.length()==0)
//		{
//			if(pds.at(i).getPinse().distanceTo(p)<distanza)
//			{
//				if (distanzaPdsLineaTeoricaTracciatura<0.4)
//				{
//					distanza=pds.at(i).getPinse().distanceTo(p);
//					indice=i;
//				
//					punto=pds.at(i).getPinse();
//				}
//			}
//		}
//	}
//
//	delete teorica;teorica=NULL;
//	intersectionPoints.setLogicalLength(0).setPhysicalLength(0);
//
//	if (indice<pds.size())
//		pd=pds.at(indice);
//
//
//	return pd;
//}
//
//

AcDbEntity *JigMensola::entity() const
{
 // check to make sure we called setEntityList
 if (!m_entityList.m_calledSetEntityList)
  AfxMessageBox (L"Error - You must call setEntityList \
  before calling asdkMultiJig::drag()");
 
 return (const_cast<asdkEntityList *>(&m_entityList));
}



AcDbObjectId JigMensola::append(AcDbDatabase *dwg,
 const ACHAR *requiredSpace)
{
	 // get the total number of entities registered
	int length = m_entityList.m_entities.length ();
	 // loop round the registered
	 // entities and add the to the space
	for (int i=0; i<length; ++i)
	{
		postToDwg ((AcDbEntity *)m_entityList.m_entities[i],
		dwg, requiredSpace);
	}
 
	 // get the id of the first entity drawn
	AcDbObjectId id =
	  ((AcDbEntity *)m_entityList.m_entities[0])->id ();
 
	 // close the entities added
	for (int i=0; i<length; ++i)
	  ((AcDbEntity *)m_entityList.m_entities[i])->close ();
 
	// return the object id
	return (id);
}



AcDbObjectId JigMensola::append(int posEnt,AcDbDatabase *dwg,
 const ACHAR *requiredSpace)
{
	 // get the total number of entities registered
	int length = m_entityList.m_entities.length ();
	 // loop round the registered
	 // entities and add the to the space
	if (posEnt<length)
	{
		postToDwg ((AcDbEntity *)m_entityList.m_entities[posEnt],
		dwg, requiredSpace);
	}
 
	 // get the id of the first entity drawn
	AcDbObjectId id =
	  ((AcDbEntity *)m_entityList.m_entities[posEnt])->id ();
 
	 ((AcDbEntity *)m_entityList.m_entities[posEnt])->close ();
 
	// return the object id
	return (id);
}



 Acad::ErrorStatus JigMensola::postToDwg (AcDbEntity *pEnt, AcDbDatabase *pDb,
 const ACHAR *requiredSpace)
{
 // if the default database is to be used
 if (pDb == NULL)
  pDb = acdbHostApplicationServices()->workingDatabase ();
 
AcDbBlockTable *blockTable = NULL;
 // get a pointer to the block table
Acad::ErrorStatus es = pDb->getBlockTable (blockTable,
  AcDb::kForRead);
 // if it failed then abort
 if (es != Acad::eOk)
  return (es);
 
AcDbBlockTableRecord *blockTableRecord = NULL;
 // now get a pointer to the model space entity records
es = blockTable->getAt (requiredSpace,
  blockTableRecord, AcDb::kForWrite);
 // can close the block table
 // itself as we don't need it anymore
blockTable->close ();
 // if it failed then abort
 if (es != Acad::eOk)
  return (es);
 // otherwise put the entity into the model space
es = blockTableRecord->appendAcDbEntity (pEnt);
 // now close it up
blockTableRecord->close();
 
 return (es);
}
AcDbDimDataPtrArray * JigMensola::dimData(const double dimScale)
{
	acutPrintf(L"\nSTARTdimData");
	int valoreQuota=quota%4;
	if (valoreQuota==0)
	{
		AcDbAlignedDimension * pDimension = new AcDbAlignedDimension;
		pDimension->setDatabaseDefaults();
		pDimension->setNormal(AcGeVector3d::kZAxis);
		pDimension->setElevation(0.0);
		pDimension->setDimscale(dimScale);
		pDimension->setHorizontalRotation(0.);
		pDimension->setDynamicDimension(true);

		AcDbObjectId idStile;

		/*ACHAR* stile=L"Standard";

		if(stile!=NULL)
			AcDbSymbolUtilities::getDimStyleId(idStile,stile,acdbHostApplicationServices()->workingDatabase());
		*/
		//mid_point(&midP,AcGePoint3d(0,0,0),AcGePoint3d(0,0,0));
		//es=quota->setDimLinePoint(midP);
		//pDimension->setDimensionStyle(idStile);

		AcDbDimData * pDimData = new AcDbDimData(pDimension);
		pDimData->setDimFocal(true);
		pDimData->setDimHideIfValueIsZero(true);
		pDimData->setDimEditable(true);
	

		 m_dimData.append(pDimData);
	}

	if (valoreQuota==1)
	{
		AcDbAlignedDimension * pDimension = new AcDbAlignedDimension;
		pDimension->setDatabaseDefaults();
		pDimension->setNormal(AcGeVector3d::kZAxis);
		pDimension->setElevation(0.0);
		pDimension->setDimscale(dimScale);
		pDimension->setHorizontalRotation(0.);
		pDimension->setDynamicDimension(true);

		AcDbObjectId idStile;

		/*ACHAR* stile=L"Standard";

		if(stile!=NULL)
			AcDbSymbolUtilities::getDimStyleId(idStile,stile,acdbHostApplicationServices()->workingDatabase());
		*/
		//mid_point(&midP,AcGePoint3d(0,0,0),AcGePoint3d(0,0,0));
		//es=quota->setDimLinePoint(midP);
		//pDimension->setDimensionStyle(idStile);

		AcDbDimData * pDimData = new AcDbDimData(pDimension);
		pDimData->setDimFocal(true);
		pDimData->setDimHideIfValueIsZero(true);
		pDimData->setDimEditable(true);
	
		 m_dimData.append(pDimData);
	}

	if (valoreQuota==2)
	{
		AcDbAlignedDimension * pDimension = new AcDbAlignedDimension;
		pDimension->setDatabaseDefaults();
		pDimension->setNormal(AcGeVector3d::kZAxis);
		pDimension->setElevation(0.0);
		pDimension->setDimscale(dimScale);
		pDimension->setHorizontalRotation(0.);
		pDimension->setDynamicDimension(true);

		AcDbObjectId idStile;

		/*ACHAR* stile=L"Standard";

		if(stile!=NULL)
			AcDbSymbolUtilities::getDimStyleId(idStile,stile,acdbHostApplicationServices()->workingDatabase());
		*/
		//mid_point(&midP,AcGePoint3d(0,0,0),AcGePoint3d(0,0,0));
		//es=quota->setDimLinePoint(midP);
		//pDimension->setDimensionStyle(idStile);

		AcDbDimData * pDimData = new AcDbDimData(pDimension);
		pDimData->setDimFocal(true);
		pDimData->setDimHideIfValueIsZero(true);
		pDimData->setDimEditable(true);
	
		 m_dimData.append(pDimData);
	}

	if (valoreQuota==3)
	{
		AcDbAlignedDimension * pDimension = new AcDbAlignedDimension;
		pDimension->setDatabaseDefaults();
		pDimension->setNormal(AcGeVector3d::kZAxis);
		pDimension->setElevation(0.0);
		pDimension->setDimscale(dimScale);
		pDimension->setHorizontalRotation(0.);
		pDimension->setDynamicDimension(true);

		AcDbObjectId idStile;

		/*ACHAR* stile=L"Standard";

		if(stile!=NULL)
			AcDbSymbolUtilities::getDimStyleId(idStile,stile,acdbHostApplicationServices()->workingDatabase());
		*/
		//mid_point(&midP,AcGePoint3d(0,0,0),AcGePoint3d(0,0,0));
		//es=quota->setDimLinePoint(midP);
		//pDimension->setDimensionStyle(idStile);

		AcDbDimData * pDimData = new AcDbDimData(pDimension);
		pDimData->setDimFocal(true);
		pDimData->setDimHideIfValueIsZero(true);
		pDimData->setDimEditable(true);
	
		 m_dimData.append(pDimData);
	}
	acutPrintf(L"\nENDdimData");
	
	return &m_dimData;


}

Acad::ErrorStatus JigMensola::setDimValue (const AcDbDimData *pDimData, const double dimValue) {
	Acad::ErrorStatus es =Acad::eOk ;
	int valoreQuota=quota%4;
	JIGCQE = true;
	acutPrintf(L"\nSTARTsetdimvalue");
	if (valoreQuota==0)
	{
		 //SAMPLE CODE:
		//- Convert the const pointer to non const
		AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;
		int inputNumber =-1 ;
		//- Find the dim data being passed so we can determine the input number
		if ( m_dimData.find (dimDataNC, inputNumber) ) {
			//- Now get the dimension
			if(inputNumber==0)
			{
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if ( pAlnDim ) {
					//- Extract the dimensions as they are now
					AcGePoint3d dimStart =pAlnDim->xLine1Point () ;
					AcGePoint3d dimEnd =pAlnDim->xLine2Point () ;
					//- Lets get the new point entered by the user 
					//AcGePoint3d dimEndNew =dimStart + (dimEnd - dimStart).normalize () * dimValue ;
					////- Finally set the end dim point
					//pAlnDim->setXLine2Point (dimEndNew) ;
					//- Now update the jig data to reflect the dynamic dimension input
					//mInputPoints [mCurrentInputLevel] =dimEndNew ;
					
					dimEndNew=dimStart;
					dimEndNew.x=dimStart.x-dimValue;
					vettore=dimEndNew-pEnd;
					//m_cursorPoint.set(dimEndNew.x,dimEndNew.y,dimEndNew.z);
					/*
					m_NEWcursorPoint.set(dimEndNew.x,dimEndNew.y,dimEndNew.z);
					pEnd = dimEndNew;*/
					pAlnDim->setXLine2Point (dimEndNew) ;
					//acutPrintf(L"\setdimvalue pEnd %.0f;%.0f;%.0f\n",pEnd.x,pEnd.y,pEnd.z);
					/*AcEdJig::DragStatus stat = AcEdJig::drag();*/
					/*pointTmp=dimEndNew*/;
				}
			}
		}
		Nsettata=1;
	}
	if (valoreQuota==1)
	{
		 //SAMPLE CODE:
		//- Convert the const pointer to non const
		AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;
		int inputNumber =-1 ;
		//- Find the dim data being passed so we can determine the input number
		if ( m_dimData.find (dimDataNC, inputNumber) ) {
			//- Now get the dimension
			if(inputNumber==0)
			{
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if ( pAlnDim ) {
					//- Extract the dimensions as they are now
					AcGePoint3d dimStart =pAlnDim->xLine1Point () ;
					AcGePoint3d dimEnd =pAlnDim->xLine2Point () ;
					//- Lets get the new point entered by the user 
					//AcGePoint3d dimEndNew =dimStart + (dimEnd - dimStart).normalize () * dimValue ;
					////- Finally set the end dim point
					//pAlnDim->setXLine2Point (dimEndNew) ;
					
					dimEndNew=dimStart;
					dimEndNew.y=dimStart.y-dimValue;
					vettore=dimEndNew-pEnd;
					m_cursorPoint=dimEndNew;
					m_NEWcursorPoint.set(dimEndNew.x,dimEndNew.y,dimEndNew.z);
					//- Now update the jig data to reflect the dynamic dimension input
					//mInputPoints [mCurrentInputLevel] =dimEndNew ;
				}
			}
		}
		Nsettata=2;
	}

	if (valoreQuota==2)
	{
		 //SAMPLE CODE:
		//- Convert the const pointer to non const
		AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;
		int inputNumber =-1 ;
		//- Find the dim data being passed so we can determine the input number
		if ( m_dimData.find (dimDataNC, inputNumber) ) {
			//- Now get the dimension
			if(inputNumber==0)
			{
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if ( pAlnDim ) {
					//- Extract the dimensions as they are now
					AcGePoint3d dimStart =pAlnDim->xLine1Point () ;
					AcGePoint3d dimEnd =pAlnDim->xLine2Point () ;
					//- Lets get the new point entered by the user 
					//AcGePoint3d dimEndNew =dimStart + (dimEnd - dimStart).normalize () * dimValue ;
					////- Finally set the end dim point
					//pAlnDim->setXLine2Point (dimEndNew) ;
					
					dimEndNew=dimStart;
					dimEndNew.x=dimStart.x+dimValue;
					vettore=dimEndNew-pEnd;
					m_cursorPoint=dimEndNew;
					m_NEWcursorPoint.set(dimEndNew.x,dimEndNew.y,dimEndNew.z);
					//- Now update the jig data to reflect the dynamic dimension input
					//mInputPoints [mCurrentInputLevel] =dimEndNew ;
				}
			}
		}
		Nsettata=3;
	}

	if (valoreQuota==3)
	{
		 //SAMPLE CODE:
		//- Convert the const pointer to non const
		AcDbDimData *dimDataNC =const_cast<AcDbDimData *>(pDimData) ;
		int inputNumber =-1 ;
		//- Find the dim data being passed so we can determine the input number
		if ( m_dimData.find (dimDataNC, inputNumber) ) {
			//- Now get the dimension
			if(inputNumber==0)
			{
				AcDbDimension *pDim =(AcDbDimension *)dimDataNC->dimension () ;
				//- Check it's the type of dimension we want
				AcDbAlignedDimension *pAlnDim =AcDbAlignedDimension::cast (pDim) ;
				//- If ok
				if ( pAlnDim ) {
					//- Extract the dimensions as they are now
					AcGePoint3d dimStart =pAlnDim->xLine1Point () ;
					AcGePoint3d dimEnd =pAlnDim->xLine2Point () ;
					//- Lets get the new point entered by the user 
					//AcGePoint3d dimEndNew =dimStart + (dimEnd - dimStart).normalize () * dimValue ;
					////- Finally set the end dim point
					//pAlnDim->setXLine2Point (dimEndNew) ;
					
					dimEndNew=dimStart;
					dimEndNew.y=dimStart.y+dimValue;
					vettore=dimEndNew-pEnd;
					m_cursorPoint=dimEndNew;
					m_NEWcursorPoint.set(dimEndNew.x,dimEndNew.y,dimEndNew.z);
					//- Now update the jig data to reflect the dynamic dimension input
					//mInputPoints [mCurrentInputLevel] =dimEndNew ;
				}
			}
		}
		Nsettata=0;
	}
	//JIGCQE = true;
	settataQuota=true;
	SETDIM=true;
	acutPrintf(L"\nENDsetdimvalue");
	return (es) ;
}
0 Likes
819 Views
0 Replies
Replies (0)