void asdktest5 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Display a dialog box to select HLR controls, the user wants to apply to the HLR engine
    AfxSetResourceHandle (_hdllInstance) ;
    CControlsDlg dlg ;
    dlg.mnControls =kProject | kEntity | kBlock | kHonorInternals ;
    if ( dlg.DoModal () != IDOK ) {
        AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;
        return ;
    }
    AfxSetResourceHandle (acedGetAcadResourceInstance ()) ;

    int control =dlg.mnControls ;
    acutPrintf (ACRX_T("\nAbout to call hidden Line calculation")) ;
    acutPrintf (ACRX_T("\nCalling with %d Entities"), collector.getInputEntityIds ().logicalLength ()) ;
    acutPrintf (ACRX_T("\nkProject %s "), control & kProject ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkShowAll %s "), control & kShowAll ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkEntity %s "), control & kEntity  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkBlock %s "), control & kBlock  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkSubentity %s "), control & kSubentity  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkHideTangents %s "), control & kHideTangents  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkCleanup %s "), control & kCleanup  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkIsolines %s "), control & kIsolines  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkUnite %s "), control & kUnite  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkReuse %s "), control & kReuse  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkProgress %s "), control & kProgress  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkHandlePoints %s "), control & kHandlePoints  ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkHonorInternals %s "), control & kHonorInternals ? ACRX_T("On") : ACRX_T("Off")) ;
    acutPrintf (ACRX_T("\nkMeshSilhouettes %s "), control & kMeshSilhouettes ? ACRX_T("On") : ACRX_T("Off")) ;
    
    //----- Ask for virtual viewport settings
    AcDbViewport *pVp =NULL ;
    if ( !pickViewport (pVp) )
        return ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (pVp, control) ;
    hlr.run (collector) ;
    delete pVp ;

    //----- The following code will collect the color of the originator entity of an edge
    //----- and will assign it to the resulting entity.
    actrTransactionManager->startTransaction () ;

    int nOutput =collector.mOutputData.logicalLength () ;
    acutPrintf (ACRX_T("\nHlr returned %d curves"), nOutput) ;
    for ( int j =0 ; j < nOutput ; j++ ) {
        AsdkHlrData *pResult =collector.mOutputData [j] ;

        AcDbEntity *pResultEntity =pResult->getResultEntity () ;
        AcDbObjectId id ;
        if ( postToDatabase (NULL, pResultEntity, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }

        actrTransactionManager->getObject ((AcDbObject *&)pResultEntity, id, AcDb::kForWrite) ;

        AcDbObjectIdArray ids =pResult->getObjectIds () ;
        int last =ids.logicalLength () - 1 ;
        AcCmColor color ;
        AcDbObjectId layerId ;
        color.setColorIndex (0) ;
        while ( last >= 0 && color.colorIndex () == 0 ) {
            AcDbObjectId innerId =ids.at (last) ;
            AcDbObject *pObj ;
            actrTransactionManager->getObject (pObj, innerId, AcDb::kForRead) ;
            AcDbEntity *pEnt =AcDbEntity::cast (pObj) ;

            color =pEnt->color () ;
            layerId =pEnt->layerId () ;
            last-- ;
        }
        if ( layerId != AcDbObjectId::kNull ) {
            pResultEntity->setColor (color) ;
            pResultEntity->setLayer (layerId) ;
        } else {
            AcDbEntity *pEnt =pResult->getEntity () ;
            if ( pEnt != NULL ) {
                pResultEntity->setColor (pEnt->color ()) ;
                pResultEntity->setLayer (pEnt->layer ()) ;
            }
        }
        pResultEntity->close () ;
    }

    actrTransactionManager->endTransaction();
}
Example #2
0
String GetSelectedExtent() {
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN) return 0;
  if (returnValue != RTNORM) {
    return L"";
  }

  if (acedSSSetFirst(selection, NULL) != RTNORM) {
    acedSSFree(selection);
    return L"";
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return L"";
  }
  
  AcDbEntity * entity;
  if ((acdbGetObjectId(idEntity, element) != Acad::eOk) || 
      (acdbOpenObject(entity, idEntity, AcDb::kForRead) != Acad::eOk)) {
    
    acedSSFree(element);
    return L"";
  }
  
  acedSSFree(element);
  
  if (!entity->isKindOf(AcDbPolyline::desc())) return L"";
  
  AcDbPolyline * poly = static_cast<AcDbPolyline*>(entity);
  if (!poly->isClosed()) return 0;
  
  String extent = L"POLYGON((";
  AcGePoint2d start;
  AcGePoint2d current;
  for (int i = 0; i < poly->numVerts(); i++) {
    poly->getPointAt(i, current);
    
    if (i > 0) {
      extent += L", ";
    } else {
      start = current;
    }
    extent += Round(current.x, 0) + L" " + Round(current.y, 0);
  }
  if (!start.isEqualTo(current)) {
    extent += L", " + Round(start.x, 0) + L" " + Round(start.y, 0);
  }
  
  extent += L"))";
  
  poly->close();
  
  return extent;
}
Example #3
0
	// - MfcArx.syj_mfc command (do not rename)
	static void MfcArxsyj_mfc(void)
	{
		// Add your code for command MfcArx.syj_mfc here
		ads_name ss;
		resbuf rb;
		AcDbObjectIdArray objIds = NULL;
		acedSSGet(NULL,NULL,NULL,NULL,ss);
		long len;
		//取得选择集的长度
		acedSSLength(ss,&len);
		//遍历选择集中的实体,将其打开并修改其颜色为红色
		for (int i =0;i<len;i++)
		{
			ads_name entres;
			AcDbObjectId objId;
			//取得选择集中实体的名称ads_name
			acedSSName(ss,i,entres);
			//取得实体的ObjectId
			acdbGetObjectId(objId,entres);
			objIds.append(objId);
		}
		acedSSFree(ss);
		CDetailShow ds(objIds,NULL,NULL);
		ds.DoModal();

	}
Example #4
0
 bool ArxEntityHelper::SelectEntities( const AcDbObjectIdArray& objIds )
{
	//acedSSSetFirst(NULL, NULL);

	if( objIds.isEmpty() ) return false;

	ads_name ss;
	//创建一个空的选择集
	if(RTNORM != acedSSAdd( NULL, NULL, ss )) return false;
	bool ret = true;
	for(int i=0;i<objIds.length();i++)
	{
		ads_name ename;
		if( Acad::eOk != acdbGetAdsName( ename, objIds[i] ) ) 
		{ 
			ret = false;;
			break;
		}
		if( RTNORM != acedSSAdd( ename, ss, ss ) )  // 添加到选择集
		{
			ret = false;;
			break;
		}
	}

	if(ret)
	{
		acedSSSetFirst( ss, NULL ); // 高亮选中
	}
	acedSSFree( ss );           // 释放选择集

	return ret;
}
    // ----- AsdkSelectionFilterUI.SubentSel command (do not rename)
    static void AsdkSelectionFilterUI_SubentSel(void)
    {
        // we have to allow duplicates; otherwise, the xref would be selectable
        // only once (because the main entity is the one that counts).

        setAllowDuplicateSelection(curDoc(), true);
        ads_name sset, eName;
        AcDbObjectId id;

        // "_:n" gives us nested entities
        //
        if (RTNORM == acedSSGet("_:n", NULL, NULL, NULL, sset))
        {
            acutPrintf("\n");
            long len = 0;
            acedSSLength(sset, &len);
            for (long i = 0; i < len; i++)// For each entity in sset
            {

                resbuf *rb = NULL;
                // We use ssnamex() here, because the regular ssname()
                // would give only the main entity (the xref)
                //
                if (RTNORM == acedSSNameX(&rb, sset, i))//Get the sub entity
                {
                    resbuf *rbWalk = rb;
                    while (NULL != rbWalk)
                    {
                        if (RTENAME == rbWalk->restype)
                        {
                            eName[0] = rbWalk->resval.rlname[0];
                            eName[1] = rbWalk->resval.rlname[1];
                            if(Acad::eOk == acdbGetObjectId(id, eName))
                            {
                                acutPrintf("Entity %d: <%x>", i, id.asOldId());
                                AcDbEntity *pEnt;
                                if (Acad::eOk == acdbOpenObject(pEnt, id, AcDb::kForRead))
                                {
                                    acutPrintf("(%s)\n", pEnt->isA()->name());
                                    pEnt->close();
                                }
                                else
                                    acutPrintf("\nCouldn't open object");
                            }
                            rbWalk = NULL; //force quit out of loop
                        }
                        else
                            rbWalk = rbWalk->rbnext;
                    }
                    acutRelRb(rb);
                }
            }
            acedSSFree(sset);
        }

        setAllowDuplicateSelection(curDoc(), false);
    }
Example #6
0
int ads_gm_write() 
{
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  
  long num = 0;
  returnValue = acedSSLength(selection, &num);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  if (num == 0) return 0;
  
  CCadEntities entities;
  
  ads_name element;
  for (long i = 0; i < num; i++) {
    acedSSName(selection, i, element);
    
    AcDbObjectId idEntity;
    if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
      acedSSFree(element);
      acedSSFree(selection);
      return 0;
    }
    
    acedSSFree(element);
    
    CCadEntity * cadEntity = CCadEntityFactory::GetCadEntity(idEntity);
    entities.push_back(cadEntity);
  }
  acedSSFree(selection);
  
  // Obtener el feature class en edición
  CFeatureClass * featureClass = 0;
  CFeatureWriter writer(featureClass);
  writer.Write(&entities);
  
  delete featureClass;
  
  return 1;
}
Example #7
0
int ads_gm_get_data() 
{
  ads_name selection;
  int returnValue = acedSSGet(_T("I"), NULL, NULL, NULL, selection);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  
  long num = 0;
  returnValue = acedSSLength(selection, &num);
  if (returnValue == RTCAN || returnValue != RTNORM) return 0;
  if (num != 1) {
    acedSSSetFirst(NULL, NULL);
    
    returnValue = acedSSGet(L"_:S", NULL, NULL, NULL, selection);
    if (returnValue == RTCAN || returnValue != RTNORM) return 0;
    
    if (acedSSSetFirst(selection, NULL) != RTNORM) {
      acedSSFree(selection);
      return 0;
    }
  }
  ads_name element;
  acedSSName(selection, 0, element);
  acedSSFree(selection);
  
  AcDbObjectId idEntity;
  if (acdbGetObjectId(idEntity, element) != Acad::eOk) {
    acedSSFree(element);
    return 0;
  }

  acedSSFree(element);
  
  CCadEntity * cadEntity = CCadEntityFactory::GetCadEntity(idEntity);
  acutPrintf((L"\n" + cadEntity->GetData().ToFormattedString() + L"\n").c_str());
  delete cadEntity;
  
  return 1;
}
void frgExtractTopologicalEntsFromLinesAlgm::_search_related_segs(AcDbObjectIdArray &ids, const AcGeLineSeg2d &seg)
{
	double tolerance = rlTolerance::equal_point();
	if (seg.length() < 2 * tolerance)
		return;

	// - 构造反选矩形
	// -- 计算四个点
	AcGePoint2d p1, p2, p3, p4;

	AcGeVector2d dir = seg.direction();
	AcGeVector2d offset = dir;
	offset.rotateBy(rlPi / 2.0);

	p1 = seg.startPoint(); p1.transformBy(-offset * tolerance);
	p2 = seg.endPoint(); p2.transformBy(-offset * tolerance);
	p3 = seg.endPoint(); p3.transformBy(offset * tolerance);
	p4 = seg.startPoint(); p4.transformBy(offset * tolerance);

	// -- 构造矩形
	ads_point _p1, _p2, _p3, _p4;
	_p1[0] = p1.x; _p1[1] = p1.y, _p1[2] = 0;
	_p2[0] = p2.x; _p2[1] = p2.y, _p2[2] = 0;
	_p3[0] = p3.x; _p3[1] = p3.y, _p3[2] = 0;
	_p4[0] = p4.x; _p4[1] = p4.y, _p4[2] = 0;
	resbuf *rect = acutBuildList(RTPOINT, _p1, RTPOINT, _p2, RTPOINT, _p3, RTPOINT, _p4, RTNONE);

	// - 交叉查询
	ads_name ss;
	int ret = acedSSGet(_T("CP"), rect, NULL, _filter, ss);
	acutRelRb(rect);
	if (ret != RTNORM)
		return;

	// - 获取查询结果
	long len = 0;
	acedSSLength(ss, &len);
	for (int i = 0; i < len; i++)
	{
		ads_name name;
		acedSSName(ss, i, name);

		AcDbObjectId id;
		if (acdbGetObjectId(id, name) == Acad::eOk)
			ids.append(id);
	}
	acedSSFree(ss);
}
Example #9
0
void CMyDlg::OnSelectLine()
{
	// TODO: Add your control notification handler code here
	ads_name adsNameSet, adsName;
	AcDbObjectId objId;
	int ret = 0;
	long lSelCnt = 0;
	AcDbEntity *pEnt = NULL;
	int nCount = m_ListCtr.GetItemCount();
	long lId;
	CString str;
	AcDbObjectId LineId;

	acDocManager->lockDocument(curDoc());

	ShowWindow(SW_HIDE);
	ret = acedSSGet(NULL, NULL, NULL, NULL, adsNameSet);
	
	if (RTNORM == ret)
	{
		m_ListCtr.SetFocus();
		acedSSLength(adsNameSet, &lSelCnt);
		for (long i = 0; i < lSelCnt; ++i)
		{
			acedSSName(adsNameSet, i, adsName);
			acdbGetObjectId(objId, adsName);
			if (nCount > 0)
			{
				for (int i = 0; i < nCount; ++i)
				{
					str = m_ListCtr.GetItemText(i, 0);
					lId = atol(str);
					LineId.setFromOldId(lId);
					if (LineId == objId)
					{				
						m_ListCtr.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
					}
				}
			}			
		}
		ShowWindow(SW_SHOW);
	}

	acedSSFree(adsName);
//	acutRelRb(stResBuf);
	acDocManager->unlockDocument(curDoc());
}
Example #10
0
/*
 * 帮助文档中acedSSSetFirst以及acedSSGetFirst
 * 要求使用它的命令应该开启ACRX_CMD_USEPICKSET和ACRX_CMD_REDRAW选项
 * 但测试结果显示,貌似不使用也可以??????
 */
 bool ArxEntityHelper::SelectEntity( const AcDbObjectId& objId )
{
    //acedSSSetFirst(NULL, NULL);

    if( objId.isNull() ) return false;

    ads_name ename;
    if( Acad::eOk != acdbGetAdsName( ename, objId ) ) return false;;

    ads_name ss;
    if( RTNORM != acedSSAdd( ename, NULL, ss ) ) return false; // 创建选择集

    acedSSSetFirst( ss, NULL ); // 高亮选中
    acedSSFree( ss );           // 释放选择集

    return true;
}
Example #11
0
bool CMakeBlkFile::SelectEnt()
{
	ads_name ssname,ename;
	AcDbObjectId objId = AcDbObjectId::kNull;
	int nRet = acedSSGet(NULL, NULL, NULL, NULL, ssname);
	if (nRet != RTNORM)
	{
		return false;
	}
	long sslen;
	acedSSLength(ssname, &sslen);
	for (int i=0; i<sslen; i++)
	{
		acedSSName(ssname, i, ename);
		acdbGetObjectId(objId, ename);
		m_objIdArrs.append(objId);
	}
	acedSSFree(ssname);
	return true;
}
	static void shYDsysXDataDel()
	{
		ads_name ssName;
		if(RTNORM == acedSSGet(":S", NULL, NULL, NULL, ssName))
		{
			AcDbObjectId tempObjId;
			ads_name ssTemp;
			long nLen=0;
			if(RTNORM != acedSSLength(ssName,&nLen)) return;
			for(int j=0; j<nLen; j++)
			{
				if(RTNORM == acedSSName(ssName,j,ssTemp)) continue;
				if(Acad::eOk != acdbGetObjectId(tempObjId, ssTemp)) continue;
				AcDbEntity* pEnt = NULL;
				if(Acad::eOk == acdbOpenObject(pEnt,tempObjId,AcDb::kForWrite))
				{
					
					resbuf* pHead = pEnt->xData(NULL);
					if(pHead == NULL)
					{
						pEnt->close(); continue;
					}
					resbuf* pNext =pHead->rbnext;
					if(pNext == NULL)
					{
						acutRelRb(pHead); pEnt->close(); continue;
					}
					while(pNext != NULL)
					{
						acutRelRb(pHead);
						pHead = pNext;
						pNext = pNext->rbnext;
					}
					pEnt->setXData(NULL);
					pEnt->close();
				}
			}
			acedSSFree(ssName);
		}
	}
void CDlgReadInfo::OnBnClickedBtnSelect()
{
	//交互选择实体
	BeginEditorCommand();

	CString strCadName;
	CComboBox* pCmb = (CComboBox*)GetDlgItem(IDC_COMBO_CADLY);
	pCmb->GetLBText(pCmb->GetCurSel(),strCadName);

	
	ads_name ssName;
	struct resbuf *filter=NULL;
	if(strCadName.CompareNoCase("所有图层") != 0)
	{
		filter=acutNewRb(AcDb::kDxfLayerName);
		filter->restype=AcDb::kDxfLayerName;
		filter->resval.rstring = (char*) malloc((strCadName.GetLength()+1)*sizeof(char));
		strcpy(filter->resval.rstring,strCadName.GetBuffer(0));
		filter->rbnext=NULL;
	}
	
	if (acedSSGet(":S", NULL, NULL, filter, ssName) != RTNORM)
	{
		acutPrintf("\n选择实体有误!");
		acedSSFree(ssName); acutRelRb(filter);
		CompleteEditorCommand();
		return;
	}
	if(filter != NULL) acutRelRb(filter);

	AcDbObjectId tempObjId;
	ads_name ssTemp;
	long nNum = 0;
	int nPos = 0;
	acedSSLength(ssName,&nNum);
	CString strSdeName,strId,strRowId;

	m_wndTree.DeleteAllItems();

	// 清空属性列表
	ResetListItems();

	for(int i=0; i<nNum; i++)
	{
		acedSSName(ssName, i, ssTemp);
		if(Acad::eOk != acdbGetObjectId(tempObjId, ssTemp)) continue;
		strId.Format("%d",tempObjId.asOldId());
		CDistXData tempXData(tempObjId,"ROWID_OBJS");
		if(tempXData.Select("SDELYNAME",strSdeName)==FALSE) continue;
		if(tempXData.Select("OBJECTID",strRowId)==FALSE) continue;
		tempXData.Close();

		HTREEITEM hItem = m_wndTree.InsertItem(strId);

		AcDbEntity *pEnt = NULL;
		if (Acad::eOk != acdbOpenObject(pEnt, tempObjId, AcDb::kForRead))
		{
			return;
		}
		pEnt->close();

		ITEM_DATA xxItemData;
		xxItemData.strID = strId;
		xxItemData.strSdelayerName = strSdeName;
		xxItemData.strCadLayerName = pEnt->layer();
		xxItemData.strRowId = strRowId;

		mapItemData[strId] = xxItemData;

		nPos++;
	}
	
	acedSSFree(ssName);

	CompleteEditorCommand();

	if (m_wndTree.GetCount() <= 0)
	{
		return;
	}

	HTREEITEM hItem = m_wndTree.GetFirstVisibleItem();

	// 显示属性
	OnSelectChanged(hItem);
}
Example #14
0
Acad::ErrorStatus
selectEntity(const AcDb::SubentType& subType,
			 AcDbFullSubentPath&     subPath)
{
	Acad::ErrorStatus acadReturnValue = Acad::eOk;

	int errStat = RTERROR;
	ads_name sset;
	AcGePoint3d pickPnt;

	struct resbuf org_osnap;
	acedGetVar(ACRX_T("OSMODE"), &org_osnap);
	struct resbuf new_osnap = org_osnap;
	new_osnap.resval.rint = 0;
	acedSetVar(ACRX_T("OSMODE"), &new_osnap);

    while ((errStat != RTNORM) && (errStat != RTCAN) && (errStat != RTREJ)
        && (errStat != RTNONE)) {
        ads_name ent_name;
        switch(subType) {
		case AcDb::kNullSubentType:
			errStat = acedEntSel(ACRX_T("\n Pick a solid\n"), ent_name, asDblArray(pickPnt));
			break;
		case AcDb::kFaceSubentType:
			errStat = acedEntSel(ACRX_T("\n Pick a face\n"), ent_name, asDblArray(pickPnt));
			break;
		case AcDb::kEdgeSubentType:
			errStat = acedEntSel(ACRX_T("\n Pick an edge\n"), ent_name, asDblArray(pickPnt));
			break;
		default:
			acutPrintf(ACRX_T("\n getPath: unsupported subentity type: %d\n"), subType);
			return Acad::eInvalidInput;
		}

        if (errStat == RTERROR) {
            struct resbuf buf_errno;
			acedGetVar(ACRX_T("ERRNO"), &buf_errno);
	        if (buf_errno.resval.rint == OL_ENTSELNULL) errStat = RTNONE;
        }
    }

	if (errStat == RTNORM) {
	    errStat = acedSSGet(NULL, asDblArray(pickPnt), NULL, NULL, sset);
	}
    acedSetVar(ACRX_T("OSMODE"), &org_osnap);

	if (errStat != RTNORM) return Acad::eAmbiguousInput;

	// Get the entity name
	struct resbuf* rb;
	errStat = acedSSNameX(&rb, sset, 0L);
    if (errStat != RTNORM) {
		acedSSFree(sset);
		return Acad::eAmbiguousInput;
    }  

	// Free the selection set
    acedSSFree(sset);

	// The selected entity is the final entry in the resbuf
	int i;
    struct resbuf* pTemp;
	for (i=1, pTemp=rb; i<3; i++, pTemp=pTemp->rbnext)
		;
	ads_name ename;
	ads_name_set(pTemp->resval.rlname, ename);

	// Get the GsMarker
	pTemp = pTemp->rbnext;
	short marker = pTemp->resval.rint;

	// Free the rb resbuf entity
	acutRelRb(rb);


	// Get the object ID of the selected entity
	AcDbObjectId objId;
	acadReturnValue = acdbGetObjectId(objId, ename);
    if (acadReturnValue != Acad::eOk) {
		acutPrintf(ACRX_T("\n acdbGetObjectId failed\n"));
		return acadReturnValue;
	}

    // Use an existing transaction if there is one;
	// else open a new one
	Adesk::Boolean ownTransaction = Adesk::kFalse;
	acadReturnValue = dbOpenTransaction(ownTransaction);
	if (acadReturnValue != Acad::eOk) {
		acutPrintf(ACRX_T("\n Error in dbOpenTransaction:"));
		errorReport((AcBr::ErrorStatus)acadReturnValue);
		return acadReturnValue;
	}
	
	// Open the object for read-only
	AcDbObject* pObj = NULL;
	acadReturnValue = actrTransactionManager->getObject(
		pObj, objId, AcDb::kForRead);
	if (acadReturnValue != Acad::eOk) {
		dbAbortTransaction(ownTransaction);
		acutPrintf(ACRX_T("\n Error in getPath:"));
		errorReport((AcBr::ErrorStatus)acadReturnValue);
		return acadReturnValue;
	}

	if (AcDbBlockReference::cast(pObj) != NULL) {
		acadReturnValue = extractSolidFromBlock(ename, subType, marker, pickPnt, subPath);
		if (acadReturnValue != Acad::eOk) {
			dbCloseTransaction(ownTransaction);
			acutPrintf(ACRX_T("\n extractSolidFromBlock failed\n"));
			return acadReturnValue;
		}
	} else {
		AcDbObjectIdArray objIdList;
		objIdList.append(objId);
		acadReturnValue = makeSubentPath(pObj, objIdList, subType, marker, pickPnt, subPath);
		if (acadReturnValue != Acad::eOk) {
			dbCloseTransaction(ownTransaction);
			acutPrintf(ACRX_T("\n makeSubentPath failed\n"));
			return acadReturnValue;
		}
	}

	// Close the transaction
	dbCloseTransaction(ownTransaction);
	
	return acadReturnValue;
}
Example #15
0
void 
polyeditCommand()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
	Adesk::Boolean	    done;
    Acad::ErrorStatus es = Acad::eOk;
    AcDbFullSubentPath nullSub;
	AcGePoint2d   savedCenter;
	AcGePoint2d   savedStartPoint;
	int	     savedNumSides;
	AcGeVector3d  savedNormal;
	char	     savedName[133];
    double savedElevation;
    
    // Select an AsdkPoly entity.
    
    AsdkPoly	 *poly = NULL;
    AcDb3dSolid  *solid = NULL;
    AcDbObjectId  objId;
    
    ads_name	  ename;
    ads_point     ptres;

    AcDbEntity* ent;

	ads_name ss ;
	if ( acedSSGet ("_I", NULL, NULL, NULL, ss) == RTNORM ) {
		long n ;
		acedSSLength (ss, &n) ;
		switch ( n ) {
			case 0:
				//----- Not possible, but ?
				break ;
			case 1:
				acedSSName (ss, 0, ename) ;

				AOK(acdbGetObjectId(objId, ename));
        
				AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
				assert(ent != NULL);
        
				poly = AsdkPoly::cast(ent);
				if (poly == NULL) {
					acutPrintf("\nNot a polygon.");
					AOK(ent->close());
				}
				break ;
			default:
				//----- If more than one entity selected, fallback in standard selection mode
				break ;
		}
		acedSSFree (ss) ;
	}

	while ( poly == NULL ) {

		switch (acedEntSel("\nSelect a poly: ", ename, ptres)) {
        
		case RTNORM:
        
			AOK(acdbGetObjectId(objId, ename));
        
			AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
			assert(ent != NULL);
        
			poly = AsdkPoly::cast(ent);
			if (poly == NULL) {
				acutPrintf("\nNot a polygon.");
				AOK(ent->close());
				continue;
			}
        
			break;
        
		case RTNONE:
		case RTCAN:
			return;
		default:
			continue;
		}
		break;
	}

    // Now we have a polygon. Start editing it.
    
    char option[256];
    
    done = Adesk::kFalse;
    interrupted = Adesk::kFalse;
    
    while (!done && !interrupted) {
        
        AOK(getEditOption(option,interrupted));
        
        if (strcmp(option, "Grow") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(growPoly(poly));
            
        } else if (strcmp(option, "Shrink") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(shrinkPoly(poly));
            
        } else if (strcmp(option, "More") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(morePoly(poly));
            
        } else if (strcmp(option, "Less") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(lessPoly(poly));
            
        } else if (strcmp(option, "Thicken") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(thickenPoly(poly, ent, savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            solid = AcDb3dSolid::cast(ent);
            assert(solid != NULL);
            poly = NULL;
            
            
            solid->draw();
            
        } else if (strcmp(option, "Flatten") == 0) {
            
            if (!ent->isKindOf(AcDb3dSolid::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(flattenPoly(solid,ent,savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            poly = AsdkPoly::cast(ent);
            assert(poly != NULL);
            solid = NULL;
            
            
        } else if (strcmp(option, "Name") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            Acad::ErrorStatus es;
            if ((es = namePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's name. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
            if ((es = stylePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's text style. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
        } else if (strcmp(option, "EXit") == 0) {
            done = Adesk::kTrue;
        } else {
            done = Adesk::kTrue;
        }
        
    }
    
    // Close the entity corresponding to the open for read right
    // after selection.
    
    AOK(ent->close());
}
Example #16
0
////////////////////////////////////////////////////////////////////////////////
// drawMaterial()
//
// Draws a cube of the dimension "dCubeSize" at the position "corner", draws the
// name of the material "sMaterial" under the cube, and applies the material
// "sMaterial" to the cube.
//
// Returns AvRetNorm unless it encounters an error in acdbEntLast(), in
// which case it returns AvRetError.
//
static AvErrorCode
drawMaterial(ads_point corner, double dCubeSize, 
             char *sMaterial, char *sLibPath)
{
    AvErrorCode    retval;
    AvMatlibParam  libParam;
    AvRmatParam    rmatParam;
    ads_name       entity,
                   selectionSet;

    drawCube(corner, dCubeSize);

    // Get the cube we just created
    //
    if (acdbEntLast(entity) != RTNORM) 
    {
        acdbFail("acdbEntLast failed\n");
        return AvRetError;
    }

    acedSSAdd(entity, NULL, selectionSet);

    drawMaterialName(corner, dCubeSize, sMaterial);

    // Retrieve the material from the library
    //
    libParam.mode = AvMatlibImport;
    libParam.libraryName = sLibPath;
    libParam.materialName = sMaterial;
    libParam.flags = AvMatlibMaterial | AvMatlibLibrary;
    if((retval = av_matlib(&libParam)) != AvRetNorm) 
    {
        acutPrintf("error: %s importing %s\n",
                   av_errorstr(retval),
                   sMaterial);
    }
    else
    {
        // Apply the material to the drawing
        //
        rmatParam.mode = AvRmatAttach;
        rmatParam.selectionSet[0] = selectionSet[0];
        rmatParam.selectionSet[1] = selectionSet[1];
        rmatParam.name = sMaterial;
        rmatParam.flags = AvRmatSelSet | AvRmatName;
        if((retval = av_rmat(&rmatParam)) != AvRetNorm) 
        {
            acutPrintf("error: %s attaching %s\n",
                       av_errorstr(retval),
                       sMaterial);
        } 
        else 
        {
            acutPrintf("attached material %s\n",
                        sMaterial);
        }
    }
    
    acedSSFree(selectionSet);

    return AvRetNorm;
}
void asdktest4 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- *** First view will be front view ***

    //----- Process hidden line removal
    AsdkHlrEngine hlrFront (
        asPnt3d (tarPt), AcGeVector3d (0, -1, 0),//AcGeVector3d (0, 0, -1),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrFront.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("FontView")) ;

    //----- *** Second view will be left view ***

    //----- Process hidden line removal

    AsdkHlrEngine hlrLeft (
        asPnt3d (tarPt), AcGeVector3d (1, 0, 0),//, AcGeVector3d (1, 0, 0),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrLeft.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("LeftView")) ;

    //----- *** Third view will be top view ***

    //----- Process hidden line removal

    AsdkHlrEngine hlrTop (
        asPnt3d (tarPt), AcGeVector3d (0, 0, 1),//, AcGeVector3d (0, -1, 0),
        kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup'
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlrTop.run (collector) ;
    AddEntityToLayer (collector, ACRX_T("TopView")) ;
}
void asdktest1 () {
    //----- Select the entities
    ads_name ss, en ;
    if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM )
        return ;

    //----- Append entity IDs to the collector
    long n ;
    AcDbObjectId id ;
    AsdkHlrCollector collector ;
    collector.setDeleteState (true) ;
    acedSSLength (ss, &n) ;
    for ( int i =0 ; i < n ; i++ ) {
        acedSSName (ss, i, en) ;
        acdbGetObjectId (id, en) ;
        collector.addEntity (id) ;
    }
    acedSSFree (ss) ;

    //----- Get current viewport settings
    struct resbuf rb;
    acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb);
    ads_point dirPt;
    acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ;
    acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb);
    ads_point tarPt;
    acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ;

    //----- Ask if non-visible edges should be created
    int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ;
    int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ;
    int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ;
    int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ;

    //----- Process hidden line removal
    AsdkHlrEngine hlr (
        asPnt3d (tarPt), asVec3d (dirPt),
        kEntity | kBlock | kSubentity | kProgress
        | (honorInt == IDYES ? kHonorInternals : 0)
        | (hidLines == IDYES ? kShowAll : 0)
        | (meshSils == IDYES ? kMeshSilhouettes : 0)
        | (unit == IDYES ? kUnite : 0)
    ) ;
    hlr.setAcisConversionProgressCallBack (progress1) ;
    hlr.setAhlProgressCallBack (progress2) ;
    hlr.setAcadConversionProgressCallBack (progress3) ;

    acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ;
    hlr.run (collector) ;
    acedRestoreStatusBar () ;

    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    n =collector.mOutputData.logicalLength () ;
    for (int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible ) {
            pEnt->setColorIndex (1) ; //----- Read
        } else if ( vis == AsdkHlrData::kInternallyHidden ) {
            if ( p->getHlrVisibility () == AsdkHlrData::kVisible )
                pEnt->setColorIndex (2) ; //----- Yellow
            else
                pEnt->setColorIndex (3) ; //----- Green
        } else {
            pEnt->setColorIndex (5) ; //----- Blue
        }

        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }
        if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) {
            acutPrintf (_T("Failed to open last added outputed curve.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ;
            if ( p->getSubentId ().type () != AcDb::kNullSubentType )
                acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ )
                acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ;
            AcDbObjectId id =ids.last () ;
            if ( !id.isNull () ) {
                AcDbEntity *ent =NULL ;
                acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ;
                id =ent->linetypeId () ;
                ent->close () ;
                if ( pEnt->upgradeOpen () == Acad::eOk )
                pEnt->setLinetype (id) ;
            }
        }

        pEnt->close () ;
    }
}