コード例 #1
0
ファイル: SelectMode.cpp プロジェクト: CassieMarie/heekscad
void CSelectMode::OnDragging( wxMouseEvent& event )
{
	if(event.MiddleIsDown())
	{
		wxPoint dm;
		dm.x = event.GetX() - CurrentPoint.x;
		dm.y = event.GetY() - CurrentPoint.y;
		if(wxGetApp().ctrl_does_rotate == event.ControlDown())
		{
			if(wxGetApp().m_rotate_mode)
			{
				wxGetApp().m_current_viewport->m_view_point.Turn(dm);
			}
			else
			{
				wxGetApp().m_current_viewport->m_view_point.TurnVertical(dm);
			}
		}
		else
		{
			wxGetApp().m_current_viewport->m_view_point.Shift(dm, wxPoint(event.GetX(), event.GetY()));
		}
		wxGetApp().m_current_viewport->m_need_update = true;
		wxGetApp().m_current_viewport->m_need_refresh = true;
	}
	else if(event.LeftIsDown())
	{
		if(wxGetApp().drag_gripper)
		{
			double to[3], from[3];
			wxGetApp().m_digitizing->digitize(wxPoint(event.GetX(), event.GetY()));
			extract(wxGetApp().m_digitizing->digitized_point.m_point, to);
			wxGetApp().grip_to = wxGetApp().m_digitizing->digitized_point.m_point;
			extract(wxGetApp().grip_from, from);
			wxGetApp().drag_gripper->OnGripperMoved(from, to);
			wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
			wxGetApp().grip_from = make_point(from);
		}
		else if(abs(button_down_point.x - event.GetX())>2 || abs(button_down_point.y - event.GetY())>2)
		{
			if(wxGetApp().m_dragging_moves_objects && !window_box_exists)
			{
				std::list<HeeksObj*> selected_objects_dragged;
				wxGetApp().m_show_grippers_on_drag = true;

				if(	wxGetApp().m_marked_list->list().size() > 0)
				{
					for(std::list<HeeksObj*>::iterator It = wxGetApp().m_marked_list->list().begin(); It != wxGetApp().m_marked_list->list().end(); It++)
					{
						HeeksObj* object = *It;
						if(object->CanBeDragged())selected_objects_dragged.push_back(object);
					}
				}
				else
				{
					MarkedObjectManyOfSame marked_object;
					wxGetApp().FindMarkedObject(button_down_point, &marked_object);
					if(marked_object.m_map.size()>0){
						HeeksObj* object = marked_object.GetFirstOfTopOnly();
						double min_depth = 0.0;
						HeeksObj* closest_object = NULL;
						while(object)
						{
							if(object->CanBeDragged())
							{
								double depth = marked_object.GetDepth();
								if(closest_object == NULL || depth<min_depth)
								{
									min_depth = depth;
									closest_object = object;
								}
							}
							object = marked_object.Increment();
						}
						if(selected_objects_dragged.size() == 0 && closest_object){
							selected_objects_dragged.push_back(closest_object);
							wxGetApp().m_show_grippers_on_drag = false;
						}
					}
				}

				if(selected_objects_dragged.size() > 0)
				{
					wxGetApp().drag_gripper = &drag_object_gripper;
					wxGetApp().m_digitizing->SetOnlyCoords(wxGetApp().drag_gripper, true);
					wxGetApp().m_digitizing->digitize(button_down_point);
					wxGetApp().grip_from = wxGetApp().m_digitizing->digitized_point.m_point;
					wxGetApp().grip_to = wxGetApp().grip_from;
					double from[3];
					from[0] = wxGetApp().grip_from.X();
					from[1] = wxGetApp().grip_from.Y();
					from[2] = wxGetApp().grip_from.Z();
					wxGetApp().drag_gripper->OnGripperGrabbed(selected_objects_dragged, wxGetApp().m_show_grippers_on_drag, from);
					wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
					double to[3];
					wxGetApp().m_digitizing->digitize(wxPoint(event.GetX(), event.GetY()));
					extract(wxGetApp().m_digitizing->digitized_point.m_point, to);
					wxGetApp().grip_to = wxGetApp().m_digitizing->digitized_point.m_point;
					extract(wxGetApp().grip_from, from);
					wxGetApp().drag_gripper->OnGripperMoved(from, to);
					wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
					return;
				}
			}

			if(window_box_exists && wxGetApp().m_mouse_move_highlighting)
			{
				m_highlighted_objects.clear();
				GetObjectsInWindow(event, m_highlighted_objects);
				wxGetApp().Repaint();
			}

			// do window selection
			if(!m_just_one)
			{
				wxGetApp().m_current_viewport->SetXOR();
				if(window_box_exists)wxGetApp().m_current_viewport->DrawWindow(window_box, true); // undraw the window
				window_box.x = button_down_point.x;
				window_box.width = event.GetX() - button_down_point.x;
				window_box.y = wxGetApp().m_current_viewport->GetViewportSize().GetHeight() - button_down_point.y;
				window_box.height = button_down_point.y - event.GetY();
				wxGetApp().m_current_viewport->DrawWindow(window_box, true);// draw the window
				wxGetApp().m_current_viewport->EndXOR();
				window_box_exists = true;
			}
		}
	}
	CurrentPoint = wxPoint(event.GetX(), event.GetY());
}
コード例 #2
0
ファイル: SelectMode.cpp プロジェクト: CassieMarie/heekscad
void CSelectMode::OnLeftDown( wxMouseEvent& event )
{
	button_down_point = wxPoint(event.GetX(), event.GetY());
	CurrentPoint = button_down_point;
	m_button_down = true;
	m_highlighted_objects.clear();

	if(wxGetApp().m_dragging_moves_objects)
	{
		MarkedObjectManyOfSame marked_object;
		wxGetApp().FindMarkedObject(button_down_point, &marked_object);
		if(marked_object.m_map.size()>0)
		{
			HeeksObj* object = marked_object.GetFirstOfTopOnly();

			if (event.ShiftDown())
			{
				// Augment the marked_object list with objects that 'look' like
				// the one selected.

				CCorrelationTool correlate(wxGetApp().m_min_correlation_factor, wxGetApp().m_max_scale_threshold, wxGetApp().m_number_of_sample_points, wxGetApp().m_correlate_by_color );
				std::list<HeeksObj *> similar_objects = correlate.SimilarSymbols( object );
				std::list<HeeksObj *>::const_iterator l_itSymbol;

				for (l_itSymbol = similar_objects.begin(); l_itSymbol != similar_objects.end(); l_itSymbol++)
				{
					HeeksObj *ob = *l_itSymbol;
					if (! wxGetApp().m_marked_list->ObjectMarked(ob))
					{
						wxGetApp().m_marked_list->Add(ob, true);
					}
				} // End for
			} // End if - then

			while(object)
			{
				if(object->GetType() == GripperType)
				{
					wxGetApp().m_current_viewport->DrawFront();
					wxGetApp().drag_gripper = (Gripper*)object;
					wxGetApp().m_digitizing->SetOnlyCoords(wxGetApp().drag_gripper, true);
					wxGetApp().m_digitizing->digitize(button_down_point);
					wxGetApp().grip_from = wxGetApp().m_digitizing->digitized_point.m_point;
					wxGetApp().grip_to = wxGetApp().grip_from;
					double from[3];
					from[0] = wxGetApp().grip_from.X();
					from[1] = wxGetApp().grip_from.Y();
					from[2] = wxGetApp().grip_from.Z();

					std::list<HeeksObj*> selected_objects;
					for(std::list<HeeksObj*>::iterator It = wxGetApp().m_marked_list->list().begin(); It != wxGetApp().m_marked_list->list().end(); It++)
					{
						HeeksObj* object = *It;
						if(object->CanBeDragged())selected_objects.push_back(object);
					}

					wxGetApp().drag_gripper->OnGripperGrabbed(selected_objects, true, from);
					wxGetApp().grip_from = gp_Pnt(from[0], from[1], from[2]);
					wxGetApp().m_current_viewport->EndDrawFront();
					return;
				}
				object = marked_object.Increment();
			}
		}
	}
}