cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Stop Rotation

agangaiah
14-Alexandrite

Stop Rotation

Hi, 

 

I am using the below script to rotate the model.

 

var timerId = -1;
var angleIncrement = 5; // degrees
var timingInterval = 30; // milliseconds

$scope.rotateModel = function(){
if (timerId > -1) {
clearInterval(timerId);
}

timerId = setInterval(function() {
if (!$scope.app.params.ry) {
$scope.app.params.ry = 0;

}
$scope.$apply(function(){
$scope.app.params.ry += angleIncrement % 360;
});
}, timingInterval);
};

 

But the below code which I using to stop rotation does not seem to work. 

$scope.stoprotate = function() {
$interval.cancel($scope.rotateModel);
}

 

Any help in this regard will be great!!!

ACCEPTED SOLUTION

Accepted Solutions

for your stoprotate function, try the following:

 

$scope.stoprotate = function() {
clearInterval(timerId);
timerId = -1;
}

View solution in original post

3 REPLIES 3

for your stoprotate function, try the following:

 

$scope.stoprotate = function() {
clearInterval(timerId);
timerId = -1;
}

agangaiah
14-Alexandrite
(To:AllanThompson)

Hi Allan,

 

Perfect, this works well.

Just another question. What if I want to reset the model to its original position? Is there a JS that can help.

 

Avinash

Hi @agangaiah ,

first I want to mention to the original question that the problem there was that you wanted to used 2 similar but different functionalities for the interval - the one setInterval /JavaScript and AngularJS's wrapper for window.setInterval which does the same but points to different handles and therefore I think you have to use only the one API. In the solution @AllanThompson  pointed to the correct Javascript API

Here is an example I used for Gauge setting where I used only the Angular Js $Interval:

$scope.timeInterval=1000
$scope.stop=undefined;

$scope.app.setArrowValue = function(val) {
 console.log("called setArrowValue("+val+")");
let scaleMin=0
let scaleMax=100
let value=val

if(val < scaleMin) value=scaleMin
if(val >scaleMax) value= scaleMax
 
 //for angleMin angle in assembly is 90
 //for angleMax angele in assembly is -90
  
  let deltaAngle= 180.0*value/(scaleMax-scaleMin)  
  let angleCalc= 90-deltaAngle
 $timeout(function () {
 //   $scope.view.wdg['arrowScale']['forceHidden'] = true;

 $scope.$applyAsync(()=>{
   console.log("called $scope.setWidgetProp rz with angleCalc="+angleCalc);
    $scope.setWidgetProp('scaleArrow', 'rz', angleCalc);                       
                         }); 
},5);  
};

//=========================================================================
$scope.app.clickToggle= function()
{
  if(!$scope.view.wdg['toggle-1']['value']==true)
  {
    //$scope.view.wdg['toggle-1']['value']=false
    $scope.view.wdg['toggle-1']['label']='stopped'
    if (angular.isDefined( $scope.stop)) {$interval.cancel($scope.stop);$scope.stop=undefined;}
  }
  else
  {
  // $scope.view.wdg['toggle-1']['value']=true
    $scope.view.wdg['toggle-1']['label']='started'
    $scope.stop =$interval(function() {
     let RandValue= parseInt(Math.random()*90+1)
     $scope.app.setArrowValue(RandValue); //set the model gauge
     $scope.app.params['GAUGEANGLE']=RandValue //set the parameter
     $scope.$applyAsync();
},$scope.timeInterval);
  }
}

So, now back to the last question regarding how to reset the original position.  When it is no zero then you have simple to  save it to an global variable before you will start your rotation function- that’s all - all things what you want to reset you can save in variables or if it is a long list then in Json File which could be loaded by the $http and sett accordingly all values

Announcements

Top Tags