Problem with figure reduction

1 view (last 30 days)
Baptiste Ranguetat
Baptiste Ranguetat on 7 Aug 2017
Commented: Jan on 10 Aug 2017
Hi, i am plotting robot position that i update with a while loop on a figure, but there is an issue. I cannot reduce the window. In fact, i can but at every new iteration the figure just come back on the foreground. Is there a solution to fix it ? Thank you, Baptiste.
  3 Comments
Baptiste Ranguetat
Baptiste Ranguetat on 7 Aug 2017
Here is my while loop
while(self.ctrl.simulateur.simulationEnCours==1)
self.ctrl.simulateur.deplacementRobot();
self.dessinerSimulation();
self.dessinerReconstruction();
set(self.lblInfoEtape,'String',['Etape ',num2str(self.ctrl.getNumeroEtapeEnCours()),' sur ',num2str(self.ctrl.getTaillePattern()),' : ',self.ctrl.getDesignationEtapeEnCours()]);
set(self.lblTimerEtape,'String',['Timer étape : ',self.convertirIterationTemps(self.ctrl.getTimerEtapeEnCours())]);
set(self.lblTimerTotal,'String',['Timer total : ',self.convertirIterationTemps(self.ctrl.getTimerPattern())]);
set(self.lblForme,'String',['Forme : ',char(self.ctrl.simulateur.piscineReconstruite.forme)]);
set(self.lblProfil,'String',['Profil : ',char(self.ctrl.simulateur.piscineReconstruite.profil)]);
set(self.lblLongueur,'String',['Longueur : ',num2str(self.ctrl.simulateur.piscineReconstruite.longueur),' mm']);
set(self.lblLargeur,'String',['Largeur : ',num2str(self.ctrl.simulateur.piscineReconstruite.largeur),' mm']);
pause(0.01);
end
Baptiste Ranguetat
Baptiste Ranguetat on 7 Aug 2017
And here are the two function i called
function dessinerReconstruction(self)
if(~isempty(self.ctrl.simulateur.piscineReconstruite.piscine))
cla(self.axeReconstruction);
[f,v] = self.ctrl.simulateur.piscineReconstruite.piscine.getFacesVertices();
patch('Faces',f,'Vertices',v,...
'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.30,...
'parent', self.axeReconstruction);
axes(self.axeReconstruction);
material('dull');
camlight('headlight');
set(self.axeReconstruction,'CameraPosition', [0 0 8000]);
end
function dessinerSimulation(self)
cla(self.axeSimulation);
%Dessin du robot
repRobot = self.ctrl.getRepresentationRobot();
vertexRobot = zeros(8,3);
for i=1:8
vertexRobot(i,:) = [repRobot(1,i) repRobot(2,i) repRobot(3,i)];
end
facesRobot = [1 2 4 3; 8 7 5 6; 1 2 6 5 ; 3 4 8 7 ; 4 2 6 8 ; 1 3 7 5];
patch('vertices',vertexRobot,...
'faces', facesRobot,...
'parent', self.axeSimulation,...
'edgecolor','w',...
'FaceLighting', 'none',...
'FaceColor', 'flat',...
'FaceVertexCData', [0 1 1 0 0.8 0.8;
0 1 1 0 0.8 0.8;
0 1 0 1 0.8 0.8]');
%Dessin de la piscine
[fPiscine,vPiscine] = self.ctrl.getFacesVerticesPiscine();
patch('Faces',fPiscine,'Vertices',vPiscine,...
'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.30,...
'parent', self.axeSimulation);
axes(self.axeSimulation);
material('dull');
camlight('headlight');
hold on;
grid on;
xlabel(self.axeSimulation, 'X (mm)');
ylabel(self.axeSimulation, 'Y (mm)');
end

Sign in to comment.

Answers (1)

Amy
Amy on 10 Aug 2017
Both of your functions include the line
axes(self.axeSimulation);
This command makes 'self.axeSimulation' the current axes AND brings its parent figure into focus, which is why your figure is returning to the foreground. If you just want to set 'self.axeSimulation' as the current axes without bringing it into focus you can replace the call to 'axes' with a call to 'set' (where 'fig' is the handle to the parent figure of 'self.axeSimulation'):
set(fig, 'CurrentAxes', self.axeSimulation);
  1 Comment
Jan
Jan on 10 Aug 2017
The 'CurrentAxes' property might be changed, during the code runs, when a user dares to click in the GUI. Better do not rely on the 'CurrentAxes', but define the 'Parent' property directly.
Unfortunately, material and camlight do not expect a Parent as input. Sigh.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!