Exemple #1
0
//---------------------------------------------------------
bool CShapes_Cut::On_Execute(void)
{
	int							Method;
	CSG_Shapes					*pExtent, *pCut;
	CSG_Parameter_Shapes_List	*pShapes, *pCuts;

	//-----------------------------------------------------
	pShapes	= Parameters("SHAPES")	->asShapesList();
	pCuts	= Parameters("CUT")		->asShapesList();
	pExtent	= Parameters("EXTENT")	->asShapes();
	Method	= Parameters("METHOD")	->asInt();

	//-----------------------------------------------------
	if( pShapes->Get_Count() > 0 )
	{
		int			iLayer;
		CSG_Rect	r(pShapes->asShapes(0)->Get_Extent());

		for(iLayer=1; iLayer<pShapes->Get_Count(); iLayer++)
		{
			r.Union(pShapes->asShapes(iLayer)->Get_Extent());
		}

		if( Get_Extent(r) )
		{
			pCuts->Del_Items();

			Cut_Set_Extent(r, pExtent, true);

			for(iLayer=0; iLayer<pShapes->Get_Count(); iLayer++)
			{
				if( m_pPolygons )
				{
					if( Cut_Shapes(m_pPolygons, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) )
						pCuts->Add_Item(pCut);
					else
						delete(pCut);
				}
				else
				{
					if( Cut_Shapes(r, Method, pShapes->asShapes(iLayer), pCut = SG_Create_Shapes()) )
						pCuts->Add_Item(pCut);
					else
						delete(pCut);
				}
			}

			return( pCuts->Get_Count() > 0 );
		}
	}

	return( false );
}
Exemple #2
0
CSG_Shapes * Cut_Shapes(CSG_Rect Extent, int Method, CSG_Shapes *pShapes)
{
	CSG_Shapes	*pCut	= SG_Create_Shapes();

	if( Cut_Shapes(Extent, Method, pShapes, pCut) )
	{
		return( pCut );
	}

	delete(pCut);

	return( NULL );
}
Exemple #3
0
//---------------------------------------------------------
CSG_Shapes * Cut_Shapes(CSG_Shapes *pPolygons, int Method, CSG_Shapes *pShapes)
{
	CSG_Shapes	*pCut	= SG_Create_Shapes();

	if( Cut_Shapes(pPolygons, Method, pShapes, pCut) )
	{
		return( pCut );
	}

	delete(pCut);

	return( NULL );
}
//---------------------------------------------------------
bool CShapes_Split::On_Execute(void)
{
	int			x, y, nx, ny, Method;
	CSG_Shapes	*pShapes, *pCut, *pExtent;

	//-----------------------------------------------------
	pShapes	= Parameters("SHAPES")	->asShapes();
	pExtent	= Parameters("EXTENT")	->asShapes();
	nx		= Parameters("NX")		->asInt();
	ny		= Parameters("NY")		->asInt();
	Method	= Parameters("METHOD")	->asInt();

	Parameters("CUTS")->asShapesList()->Del_Items();

	//-----------------------------------------------------
	if( pShapes->is_Valid() )
	{
		double		dx, dy;
		TSG_Rect	r;

		dx	= pShapes->Get_Extent().Get_XRange() / nx;
		dy	= pShapes->Get_Extent().Get_YRange() / ny;

		for(y=0; y<ny && Process_Get_Okay(false); y++)
		{
			r.yMin	= pShapes->Get_Extent().Get_YMin() + y * dy;
			r.yMax	= r.yMin + dy;

			for(x=0; x<nx && Process_Get_Okay(false); x++)
			{
				r.xMin	= pShapes->Get_Extent().Get_XMin() + x * dx;
				r.xMax	= r.xMin + dx;

				Cut_Set_Extent(r, pExtent, y == 0 && x == 0);

				Process_Set_Text(CSG_String::Format(SG_T("%d/%d"), y * nx + (x + 1), nx * ny));

				if( (pCut = Cut_Shapes(r, Method, pShapes)) != NULL )
				{
					pCut->Set_Name(CSG_String::Format(SG_T("%s [%d][%d]"), pShapes->Get_Name(), 1 + x, 1 + y));

					Parameters("CUTS")->asShapesList()->Add_Item(pCut);
				}
			}
		}

		return( true );
	}

	return( false );
}
//---------------------------------------------------------
bool CShapes_Cut_Interactive::On_Execute_Position(CSG_Point ptWorld, TSG_Module_Interactive_Mode Mode)
{
	switch( Mode )
	{
	//-----------------------------------------------------
	case MODULE_INTERACTIVE_LDOWN:
		if( m_bDown == false )
		{
			m_bDown	= true;
			m_pDown	= ptWorld;
		}

		return( true );

	//-----------------------------------------------------
	case MODULE_INTERACTIVE_LUP:
		if( m_bDown == true )
		{
			m_bDown	= false;

			CSG_Rect	r(m_pDown, ptWorld);

			if( Get_Extent(r) )
			{
				if( Cut_Set_Extent(r, m_pExtent, true) )
				{
					DataObject_Update(m_pExtent);
				}

				if( Cut_Shapes(r, m_Method, m_pShapes, m_pCut) )
				{
					DataObject_Update(m_pCut);
				}
				else
				{
					Message_Add(_TL("No shapes in selection"));
				}
			}
		}

		return( true );
	}

	return( true );
}