void frgExtractTopologicalEntsFromLinesAlgm::_extract_vertices_from_lines(std::vector<Vertex2dsOnSegment2d> &seg_pnts_pairs,
	const AcDbObjectIdArray &ids)
{
	AcDbEntity *entity = NULL;
	acedSetStatusBarProgressMeter(_T("正在提取每根线段上的节点..."), 0, ids.length());
	for (int i = 0; i < ids.length(); i++)
	{
		acdbOpenAcDbEntity(entity, ids[i], AcDb::kForRead);
		if (entity == NULL)
			continue;

		if (entity->isA() != AcDbLine::desc())
		{
			entity->close();
			continue;
		}
		AcDbLine *line = (AcDbLine *)entity;

		Vertex2dsOnSegment2d stru;
		stru.seg.set(AcGePoint2d(line->startPoint().x, line->startPoint().y),
			AcGePoint2d(line->endPoint().x, line->endPoint().y));
		entity->close();

		_extract_from_seg(stru);
		seg_pnts_pairs.push_back(stru);
		acedSetStatusBarProgressMeterPos(i);
	}
	acedRestoreStatusBar();
}
void frgExtractTopologicalEntsFromLinesAlgm::_add_connections(const std::vector<Vertex2dsOnSegment2d> &seg_pnts_pairs)
{
	acedSetStatusBarProgressMeter(_T("正在梳理点、线的拓扑关系..."), 0, (int)seg_pnts_pairs.size());
	for (int i = 0; i < seg_pnts_pairs.size(); i++)
	{
		const Vertex2dsOnSegment2d &value = seg_pnts_pairs[i];
		if (value.vertex2ds.size() < 2)
			continue;
		std::map<double, rlVertex2d *, rl_double_sort1>::const_iterator it = value.vertex2ds.begin(), pos = it;
		pos++;
		for (; pos != value.vertex2ds.end(); ++pos, ++it)
		{
			rlVertex2d *v1 = it->second;
			rlVertex2d *v2 = pos->second;
			if (v1 == NULL || v2 == NULL)
			{
				assert(false);
				continue;
			}

			if (v1->has_coedge(v2))
				continue;

			rlEdge2d *_seg = _topologies->_new<rlEdge2d>();
			_seg->set_v1(v1->id());
			_seg->set_v2(v2->id());

			v1->insert(_seg->id());
			v2->insert(_seg->id());
		}
		acedSetStatusBarProgressMeterPos(i);
	}
	acedRestoreStatusBar();
}
示例#3
0
//////////////////////////////////////////////////////////////
//
// Standard C Test function
//
//////////////////////////////////////////////////////////////
void Test()
{
    acutPrintf( "Running Progress Meter...\n" );

    acedSetStatusBarProgressMeter("Test Progress Bar", 0, 100);
    for(int i =0; i <= 100; i++) {
        Sleep(100);
        acedSetStatusBarProgressMeterPos(i);
    }
    acedRestoreStatusBar();
}
void frgExtractTopologicalEntsFromLinesAlgm::_addto_rtree(std::vector<Vertex2dsOnSegment2d> &seg_pnts_pairs)
{
	acedSetStatusBarProgressMeter(_T("正在增加每个节点到Rtree树中..."), 0, (int)seg_pnts_pairs.size());
	for (int i = 0; i < seg_pnts_pairs.size(); i++)
	{
		Vertex2dsOnSegment2d &value = seg_pnts_pairs[i];
		_addto_rtree(value);
		acedSetStatusBarProgressMeterPos(i);
	}
	acedRestoreStatusBar();
}
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 () ;
    }
}
void frgExtractTopologicalEntsFromLinesAlgm::_clear_inner_vertices_on_lines()
{
	// - 查找符合条件的点
	std::set<rlVertex2d *> filtered_vertices;

	const std::map<rlId, rlVertex2d*> &ptrs = _topologies->vertices();
	acedSetStatusBarProgressMeter(_T("正在查找待合并的节点..."), 0, (int)ptrs.size());
	std::map<rlId, rlVertex2d*>::const_iterator it = ptrs.begin();
	for (int i=0; it != ptrs.end(); ++it, i++)
	{
		rlVertex2d *v = it->second;
		if (_is_colinear_vertex(v) == false)
			continue;
		filtered_vertices.insert(v);
		acedSetStatusBarProgressMeterPos(i);
	}
	acedRestoreStatusBar();

	// - 处理每一个节点
	acedSetStatusBarProgressMeter(_T("正在合并每一个查找出来的节点..."), 0, (int)filtered_vertices.size());
	std::set<rlVertex2d *>::const_iterator pos = filtered_vertices.begin();
	for (int i = 0; pos != filtered_vertices.end(); ++pos, i++)
	{
		rlVertex2d *v = *pos;

		// -- 获取该节点相邻的节点
		const std::set<rlId> &edges = v->edges();
		rlId eId1 = *edges.begin();
		rlId eId2 = *edges.rbegin();

		rlEdge2d *e1 = _topologies->get<rlEdge2d *>(eId1);
		rlEdge2d *e2 = _topologies->get<rlEdge2d *>(eId2);
		if (e1 == NULL || e2 == NULL)
		{
			assert(false);
			continue;
		}

		rlId vId1 = 0, vId2 = 0;
		if (v->has_another_end(vId1, e1) == false || v->has_another_end(vId2, e2) == false)
			continue;

		rlVertex2d *v1 = _topologies->get<rlVertex2d *>(vId1);
		rlVertex2d *v2 = _topologies->get<rlVertex2d *>(vId2);
		if (v1 == NULL || v2 == NULL)
		{
			assert(false);
			continue;
		}

		// -- 删除旧有的关系,新增新关系
		// --- 删除相邻点关联的线段id
		v1->erase(eId1);
		v2->erase(eId2);

		// --- 删除节点
		_remove_from_rtee(Point_2d(v->x(), v->y()));
		_topologies->_delete(v);

		// --- 删除两个线段
		_topologies->_delete(e1);
		_topologies->_delete(e2);

		// --- 新增线段
		rlEdge2d *e = _topologies->_new<rlEdge2d>();
		e->set_v1(vId1);
		e->set_v2(vId2);

		v1->insert(e->id());
		v2->insert(e->id());
		acedSetStatusBarProgressMeterPos(i);
	}
	acedRestoreStatusBar();
}