Beispiel #1
0
	void Run()
	{
	    CBox bounding_box;

	    for (HeeksObj *object = m_pThis->GetFirstChild(); object != NULL; object = m_pThis->GetNextChild())
	    {
                object->GetBox(bounding_box);
		}

        // add tool radius all around the box
        if(bounding_box.m_valid)
        {
            CTool *pTool = CTool::Find(m_pThis->m_tool_number);
            if(pTool)
            {
                double extra = pTool->m_params.m_diameter/2 + 0.01;
                bounding_box.m_x[0] -= extra;
                bounding_box.m_x[1] -= extra;
                bounding_box.m_x[3] += extra;
                bounding_box.m_x[4] += extra;
            }
        }

	    m_pThis->m_params.m_box = bounding_box;
		m_pThis->SetDepthOpParamsFromBox();
	}
Beispiel #2
0
static void GetWorldBox(CBox &box)
{
	// gets the extents of the volume of all the solids
	for(HeeksObj* object = wxGetApp().GetFirstChild(); object != NULL; object = wxGetApp().GetNextChild())
	{
		if(object->GetIDGroupType() == SolidType)
		{
			object->GetBox(box);
		}
	}
}
Beispiel #3
0
void ObjList::GetBox(CBox &box)
{
	std::list<HeeksObj*>::iterator It;
	for(It=m_objects.begin(); It!=m_objects.end() ;It++)
	{
		HeeksObj* object = *It;
		if(object->OnVisibleLayer() && object->m_visible)
		{
		    if (It == m_objects.begin())
		    {
		        object->GetBox(box);
		    }
		    else
		    {
                CBox new_box;
                object->GetBox(new_box);
                box.Insert(new_box);
		    }
		}
	}
}
Beispiel #4
0
CWaterline::CWaterline(const std::list<int> &solids, const int tool_number)
    :CDepthOp(GetTypeString(), NULL, tool_number, WaterlineType), m_solids(solids)
{
	ReadDefaultValues();

	// set m_box from the extents of the solids
	for(std::list<int>::const_iterator It = solids.begin(); It != solids.end(); It++)
	{
		int solid = *It;
		HeeksObj* object = heeksCAD->GetIDObject(SolidType, solid);
		if(object)
		{
			if(object->GetType() == StlSolidType)
			{
				object->GetBox(m_params.m_box);
			}
			else
			{
				double extents[6];
				if(heeksCAD->BodyGetExtents(object, extents))
				{
					m_params.m_box.Insert(CBox(extents));
				}
			}

			Add(object, NULL);
		}
	}
	m_solids.clear();

	SetDepthOpParamsFromBox();

	// add tool radius all around the box
	if(m_params.m_box.m_valid)
	{
		CTool *pTool = CTool::Find(m_tool_number);
		if(pTool)
		{
			double extra = pTool->m_params.m_diameter/2 + 0.01;
			m_params.m_box.m_x[0] -= extra;
			m_params.m_box.m_x[1] -= extra;
			m_params.m_box.m_x[3] += extra;
			m_params.m_box.m_x[4] += extra;
		}
	}
}
Beispiel #5
0
static void	WriteSolids(std::wofstream &ofs)
{

	std::set<int> stock_ids;
	wxGetApp().m_program->Stocks()->GetSolidIds(stock_ids);
	for(std::set<int>::iterator It = stock_ids.begin(); It != stock_ids.end(); It++)
	{
		int id = *It;
		HeeksObj* object = wxGetApp().GetIDObject(SolidType, id);
		if(object)
		{
			CBox box;
			object->GetBox(box);
			ofs<<"voxelcut.set_current_color("<<object->GetColor()->COLORREF_color()<<")\n";
			double c[3];
			box.Centre(c);
			ofs<<"toolpath.coords.add_block("<<c[0]<<", "<<c[1]<<", "<<box.MinZ()<<", "<<box.Width()<<", "<<box.Height()<<", "<<box.Depth()<<")\n";
		}
	}
}
Beispiel #6
0
/**
	Find out how high up all the objects are for this operation.   From this we
	will determine how far to retract the  tool so as not to hit
	them during rapid movements.
 */
double CAdaptive::GetMaxHeight( const int object_type, const std::list<int> & object_ids )
{
	// Look through the objects that make up the model and find a safe height.
	bool l_bValueUnset = true;
	double max_z = -999999;
	for (std::list<int>::const_iterator l_itObjectID = object_ids.begin(); l_itObjectID != object_ids.end(); l_itObjectID++)
	{
		HeeksObj *ob = heeksCAD->GetIDObject( object_type, *l_itObjectID );
		if (ob != NULL)
		{
			CBox bbox;
			ob->GetBox( bbox );
			{
				if ((l_bValueUnset) || (bbox.MaxZ() > max_z))
				{
					max_z = bbox.MaxZ();
					l_bValueUnset = false;
				} // End if - then
			} // End if - then
		} // End if - then
	} // End for

	return(max_z);
} // End GetMaxHeight() method
Beispiel #7
0
void CSketchOp::GetBox(CBox &box)
{
	HeeksObj* sketch = heeksCAD->GetIDObject(SketchType, m_sketch);
	if (sketch)sketch->GetBox(box);
}
Beispiel #8
0
/**
 * 	This method looks through the symbols in the list.  If they're PointType objects
 * 	then the object's location is added to the result set.  If it's a circle object
 * 	that doesn't intersect any other element (selected) then add its centre to
 * 	the result set.  Finally, find the intersections of all of these elements and
 * 	add the intersection points to the result vector.
 */
/* static */ std::vector<CNCPoint> CDrilling::FindAllLocations(
                    ObjList *parent,
                    const CNCPoint starting_location, // = CNCPoint(0.0, 0.0, 0.0)
                    const bool sort_locations, // = false
                    std::list<int> *pToolNumbersReferenced /* = NULL */ )
{
	std::vector<CNCPoint> locations;
	parent->ReloadPointers();   // Make sure our integer lists have been converted into children first.

	// Look to find all intersections between all selected objects.  At all these locations, create
	// a drilling cycle.

	std::list<HeeksObj *> lhs_children;
	std::list<HeeksObj *> rhs_children;
	for (HeeksObj *lhsPtr = parent->GetFirstChild(); lhsPtr != NULL; lhsPtr = parent->GetNextChild())
	{
	    lhs_children.push_back( lhsPtr );
	    rhs_children.push_back( lhsPtr );
	}

	for (std::list<HeeksObj *>::iterator itLhs = lhs_children.begin(); itLhs != lhs_children.end(); itLhs++)
	{
	    HeeksObj *lhsPtr = *itLhs;
		bool l_bIntersectionsFound = false;	// If it's a circle and it doesn't
							// intersect anything else, we want to know
							// about it.

		if (lhsPtr->GetType() == PointType)
		{
			double pos[3];
			lhsPtr->GetStartPoint(pos);

			// Copy the results in ONLY if each point doesn't already exist.
			if (std::find( locations.begin(), locations.end(), CNCPoint( pos ) ) == locations.end())
			{
				locations.push_back( CNCPoint( pos ) );
			} // End if - then

			continue;	// No need to intersect a point with anything.
		} // End if - then

        for (std::list<HeeksObj *>::iterator itRhs = rhs_children.begin(); itRhs != rhs_children.end(); itRhs++)
        {
            HeeksObj *rhsPtr = *itRhs;

			if (lhsPtr == rhsPtr) continue;
			if (lhsPtr->GetType() == PointType) continue;	// No need to intersect a point type.

            std::list<double> results;

            if ((lhsPtr != NULL) && (rhsPtr != NULL) && (lhsPtr->Intersects( rhsPtr, &results )))
            {
				l_bIntersectionsFound = true;
                while (((results.size() % 3) == 0) && (results.size() > 0))
                {
                    CNCPoint intersection;

                    intersection.SetX( *(results.begin()) );
                    results.erase(results.begin());

                    intersection.SetY( *(results.begin()) );
                    results.erase(results.begin());

                    intersection.SetZ( *(results.begin()) );
                    results.erase(results.begin());

					// Copy the results in ONLY if each point doesn't already exist.
					if (std::find( locations.begin(), locations.end(), intersection ) == locations.end())
					{
						locations.push_back(intersection);
					} // End if - then
				} // End while
			} // End if - then
		} // End for

		if (! l_bIntersectionsFound)
		{
			// This element didn't intersect anything else.  If it's a circle
			// then add its centre point to the result set.

			if (lhsPtr->GetType() == CircleType)
			{
				double pos[3];
				if ((lhsPtr != NULL) && (heeksCAD->GetArcCentre( lhsPtr, pos )))
				{
					// Copy the results in ONLY if each point doesn't already exist.
					if (std::find( locations.begin(), locations.end(), CNCPoint( pos ) ) == locations.end())
					{
						locations.push_back( CNCPoint( pos ) );
					} // End if - then
				} // End if - then
			} // End if - then


			if (lhsPtr->GetType() == SketchType)
			{
				CBox bounding_box;
				lhsPtr->GetBox( bounding_box );
				double pos[3];
				bounding_box.Centre(pos);
				// Copy the results in ONLY if each point doesn't already exist.
				if (std::find( locations.begin(), locations.end(), CNCPoint( pos ) ) == locations.end())
				{
					locations.push_back( CNCPoint( pos ) );
				} // End if - then
			} // End if - then

			if (lhsPtr->GetType() == ProfileType)
			{
				std::vector<CNCPoint> starting_points;
				CMachineState machine;
#ifndef STABLE_OPS_ONLY
				CFixture perfectly_aligned_fixture(NULL,CFixture::G54, false, 0.0);
				machine.Fixture(perfectly_aligned_fixture);
#endif

				// to do, make this get the starting point again
				//((CProfile *)lhsPtr)->AppendTextToProgram( starting_points, &machine );

				// Copy the results in ONLY if each point doesn't already exist.
				for (std::vector<CNCPoint>::const_iterator l_itPoint = starting_points.begin(); l_itPoint != starting_points.end(); l_itPoint++)
				{
					if (std::find( locations.begin(), locations.end(), *l_itPoint ) == locations.end())
					{
						locations.push_back( *l_itPoint );
					} // End if - then
				} // End for
			} // End if - then

            if (lhsPtr->GetType() == DrillingType)
            {
                // Ask the Drilling object what reference points it uses.
                if ((((COp *) lhsPtr)->m_tool_number > 0) && (pToolNumbersReferenced != NULL))
                {
                    pToolNumbersReferenced->push_back( ((COp *) lhsPtr)->m_tool_number );
                } // End if - then

                std::vector<CNCPoint> holes = CDrilling::FindAllLocations((CDrilling *)lhsPtr, starting_location, false, pToolNumbersReferenced);
                for (std::vector<CNCPoint>::const_iterator l_itHole = holes.begin(); l_itHole != holes.end(); l_itHole++)
                {
                    if (std::find( locations.begin(), locations.end(), *l_itHole ) == locations.end())
                    {
                        locations.push_back( *l_itHole );
                    } // End if - then
                } // End for
            } // End if - then

#ifndef STABLE_OPS_ONLY
            if (lhsPtr->GetType() == CounterBoreType)
            {
                std::vector<CNCPoint> holes = CDrilling::FindAllLocations((CCounterBore *)lhsPtr, starting_location, false, NULL);
                for (std::vector<CNCPoint>::const_iterator l_itHole = holes.begin(); l_itHole != holes.end(); l_itHole++)
                {
                    if (std::find( locations.begin(), locations.end(), *l_itHole ) == locations.end())
                    {
                        locations.push_back( *l_itHole );
                    } // End if - then
                } // End for
            } // End if - then
#endif

		} // End if - then
	} // End for

	if (sort_locations)
	{
		// This drilling cycle has the 'sort' option turned on.
		//
		// If the sorting option is turned off then the points need to be returned in order of the m_symbols list.  One day,
		// we will allow the operator to re-order the m_symbols list by using a drag-n-drop operation on the sub-elements
		// in the menu.  When this is done, the operator's decision as to order should be respected.  Until then, we can
		// use the 'sort' option in the drilling cycle's parameters.

		for (std::vector<CNCPoint>::iterator l_itPoint = locations.begin(); l_itPoint != locations.end(); l_itPoint++)
		{
			if (l_itPoint == locations.begin())
			{
				// It's the first point.
				CNCPoint reference_location(0.0, 0.0, 0.0);
                reference_location = starting_location;

				sort_points_by_distance compare( reference_location );
				std::sort( locations.begin(), locations.end(), compare );
			} // End if - then
			else
			{
				// We've already begun.  Just sort based on the previous point's location.
				std::vector<CNCPoint>::iterator l_itNextPoint = l_itPoint;
				l_itNextPoint++;

				if (l_itNextPoint != locations.end())
				{
					sort_points_by_distance compare( *l_itPoint );
					std::sort( l_itNextPoint, locations.end(), compare );
				} // End if - then
			} // End if - else
		} // End for
	} // End if - then

	return(locations);
} // End FindAllLocations() method
Beispiel #9
0
unsigned int CProfile::GetNumSketches()
{
	unsigned int num_sketches = 0;
#ifdef OP_SKETCHES_AS_CHILDREN
    for (HeeksObj *object = GetFirstChild(); object != NULL; object = GetNextChild())
    {
#else
	for (std::list<int>::iterator It = m_sketches.begin(); It != m_sketches.end(); It++)
    {
		HeeksObj* object = heeksCAD->GetIDObject(SketchType, *It);
#endif
		if(object && object->GetType() == SketchType)num_sketches++;
	}
	return num_sketches;
}

/**
	The old version of the CDrilling object stored references to graphics as type/id pairs
	that get read into the m_symbols list.  The new version stores these graphics references
	as child elements (based on ObjList).  If we read in an old-format file then the m_symbols
	list will have data in it for which we don't have children.  This routine converts
	these type/id pairs into the HeeksObj pointers as children.
 */
#ifdef OP_SKETCHES_AS_CHILDREN
void CProfile::ReloadPointers()
{
	for (Sketches_t::iterator symbol = m_sketches.begin(); symbol != m_sketches.end(); symbol++)
	{
		HeeksObj *object = heeksCAD->GetIDObject( SketchType, *symbol );
		if (object != NULL)
		{
			Add( object, NULL );
		}
	}

	m_sketches.clear();	// We don't want to convert them twice.

	CDepthOp::ReloadPointers();
}
#endif

/**
	If it's an 'inside' profile then we need to make sure the auto_roll_radius is not so large
	that it's going to gouge the part outside the sketch's area.  This routine only
	reduces the auto_roll_radius.  Its value is not changed unless a gouge scenario is detected.
 */
std::list<wxString> CProfile::ConfirmAutoRollRadius(const bool apply_changes)
{
#ifdef UNICODE
			std::wostringstream l_ossChange;
#else
			std::ostringstream l_ossChange;
#endif

	std::list<wxString> changes;

	if (m_profile_params.m_tool_on_side == CProfileParams::eRightOrInside)
	{
		// Look at the dimensions of the sketches as well as the diameter of the bit to decide if
		// our existing m_auto_roll_radius is too big for this profile.  If so, reduce it now.
		CTool *pTool = NULL;
		if ((m_tool_number > 0) && ((pTool = CTool::Find(m_tool_number)) != NULL))
		{
			for (std::list<int>::iterator l_itSketchId = m_sketches.begin(); l_itSketchId != m_sketches.end(); l_itSketchId++)
			{
				HeeksObj *sketch = heeksCAD->GetIDObject( SketchType, *l_itSketchId );
				if (sketch != NULL)
				{
					CBox bounding_box;
					sketch->GetBox( bounding_box );

					double min_distance_across = (bounding_box.Height() < bounding_box.Width())?bounding_box.Height():bounding_box.Width();
					double max_roll_radius = (min_distance_across - (pTool->CuttingRadius() * 2.0)) / 2.0;

					if (max_roll_radius < m_profile_params.m_auto_roll_radius)
					{
						l_ossChange << "Need to adjust auto_roll_radius for profile id=" << m_id << " from "
								<< m_profile_params.m_auto_roll_radius << " to " << max_roll_radius << "\n";
						changes.push_back(l_ossChange.str().c_str());

						if (apply_changes)
						{
							m_profile_params.m_auto_roll_radius = max_roll_radius;
						} // End if - then
					}
				} // End if - then
			} // End for
		} // End if - then
	} // End if - then

	return(changes);

} // End ConfirmAutoRollRadius() method